Lua Programming Help Thread
This is a discussion on Lua Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; hey guys. Im making a sort of little football (soccer) game. I want the first version to be fairly simple. ...
-
04-09-2007, 09:03 AM #6721Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
hey guys. Im making a sort of little football (soccer) game. I want the first version to be fairly simple.
I want it so when the guy runs into the ball that it starts moving and eventually stops. I know how to do collision. I just wondered what i would type to make the ball move based on where the player collides with the ball.
-
04-09-2007, 10:26 AM #6722Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
you could do a line projection path. Take the coordinates of the player and the coordinates of the ball and create a line formula. Then using that formula calculate a travel path and have the ball travel at whatever speed you like down that path. Gotta love algebra
Zitat von eldiablov
-
04-09-2007, 10:47 AM #6723Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
i am good at algebra. Could you give me some sort of psuedo code or something?
Could you tell me at least how i would create this formula ?
-
04-09-2007, 10:59 AM #6724
to take the angle the player got the ball you should use atan2
Zitat von eldiablov
hitangle = math.atan2(playerx-ballx,playery-bally)
then based on that angle you can calculate the proyection path...
but its more complex.. you betther see the phicis of a pool game wher a ball hits another ball using ball 1 speed ball 2 speed, ball 1 mass ball 2 mass, and the hitangle to calculate the correct angle of proyection..
i recomend you to move the ball not whit ball.x = ball.x+1 bether to do like..
thant should move the ball in angle 45 and whit a speed of 5Code:ballangle = 45 ballspeed = 5 ballx = ballx+math.cos(ballangle)*ballspeed bally = bally+math.sin(ballangle)*ballspeed
i strongly recomend to see pool game...
-
04-09-2007, 11:06 AM #6725Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
Ok. Any recommendations on where i can see something like this ?
With this way does it mean i dont need collision checks ?
-
04-09-2007, 11:17 AM #6726
of course you need colission chek,, but once it colide, you must calculate the ball new proyection angle. some interesting stuff on pool physics:
Zitat von eldiablov
http://library.thinkquest.org/C006300/main.htm
here go to : momentum, collision , conservatin of the momentum.
read thiss too..
http://www.billiardworld.com/physics.html
well letme see for and example a did som years ago fo another language,,, or search for a pool game made in lua
just read and read and test.
-
04-09-2007, 11:17 AM #6727
Of course you do............
Zitat von eldiablov
edit: nvm I was beat牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-09-2007, 11:21 AM #6728Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
thanks very much ahrimanes.
Im reading. Now.
I finished reading this one.
http://www.billiardworld.com/physics.html
and am looking at the formula on the other one but find them .... difficult.Geändert von eldiablov (04-09-2007 um 11:31 AM Uhr)
-
04-09-2007, 11:42 AM #6729QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
eldiablov: I recommend you use vector math instead, it is faster and once you have the base concepts, a lot easier to use.
Also, I wouldn't recommend trying to make this too realistic, ever played sensible soccer? Fake physics all the way and it was still enjoyable.[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
04-09-2007, 11:46 AM #6730Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
I dont planning on making it to realistic. Thanks Yaustar. I'll look at both and see which is easier to understand. :)
Yaustar im only getting vector for 3d games. Does this matter ?
-
04-09-2007, 12:04 PM #6731
eldiablov check this out
http://www.phy.ntnu.edu.tw/ntnujava/...hp?topic=120.0
by the way im in the same position of Yaustar...
i think the ball must go foward whit the same angle of the player, then just make the speed alitel more big than the player.. and then the ball will lose speed simulating friction...
see this alogrithn
and calculate movemente of the ball like i show back there whit sin cos...Code:if collide (player, ball) then ball angle = player angle ball speed = player speed * 1.5 end if if ball speed > 0 then ball speed = ballspeed - 1 if ball speed < 0 then ball speed = 0
Geändert von ahrimanes (04-09-2007 um 12:15 PM Uhr)
-
04-09-2007, 12:06 PM #6732Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
ty.
Loading takes long on java
reading this aswell.
http://physics.about.com/od/mathemat...ctorMath_4.htm
am i going in the right direction ?
-
04-09-2007, 12:28 PM #6733
is this correct?:
Timer = 0
while true do
pad = Controls.read()
if pad:cross() then
Timer = Timer.start()
end
if Timer == 10 then
player.y = player.y - 20
Timer = Timer.stop()
Timer = 0
end
-
04-09-2007, 12:48 PM #6734QJ Gamer Gold
- Registriert seit
- Aug 2006
- Ort
- Under Your Bed
- Beiträge
- 3.083
- Points
- 12.189
- Level
- 72
- Downloads
- 0
- Uploads
- 0
youresam or anybody what would I do in creating the lrx for compressing and uncompressing zip files would anonymous tipster's .zip source help or is making lrx's for lua different...
-
04-09-2007, 01:07 PM #6735QJ Gamer Green
- Registriert seit
- Nov 2005
- Ort
- Sweden
- Beiträge
- 460
- Points
- 6.520
- Level
- 52
- Downloads
- 0
- Uploads
- 0
It should be like this:
Zitat von moncristo_da_dev
Code:Timer = Timer.new() while true do Timer:start() pad = Controls.read() if Timer:time() >= 10 then --I suggest you put the value 10 higher, because the timer counts in milliseconds. player.y = player.y - 20 Timer:reset() end end
[CENTER]Some of my homebrew Applications/Games:
[URL=http://forums.qj.net/showthread.php?t=47294&page=1&pp=10]Planet Fighter[/URL] | [URL=http://forums.qj.net/showthread.php?p=641672#post641672]Graphic Creator (V2.0)[/URL] | [URL=http://forums.qj.net/showthread.php?p=512717]Fire Pong[/URL] | [B][URL="http://forums.qj.net/f-psp-development-forum-11/t-release-brushes-v20-99207.html#post1430891"][COLOR="Red"][SIZE="3"]Brushes v2.0[/COLOR][/SIZE][/B][/URL] [URL="http://forums.qj.net/f-psp-development-forum-11/t-release-brushes-v20-99207.html"][B][SIZE="2"][COLOR="Black"]Released![/COLOR][/SIZE][/B][/URL]
[URL="http://haxxblaster.2u.se/"][COLOR="black"][FONT="Arial Black"]www.HaxxBlaster.com[/FONT][/COLOR][/URL]
[URL="http://forums.qj.net/f-psp-development-forum-11/t-release-brushes-v20-99207.html"][IMG]http://img19.imageshack.us/img19/1346/brushesbannerqz3.png[/IMG][/URL][/CENTER]
-
04-09-2007, 01:32 PM #6736QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
eldiablov: no. 3D is just 2D minus one dimension. Just leave the Z componment as 0.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
04-09-2007, 03:05 PM #6737Developer

- Registriert seit
- Oct 2006
- Ort
- San Diego
- Beiträge
- 177
- Points
- 4.205
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Just for fun, heres a way to do it using simple math.
Zitat von eldiablov
Was thinking about this while at work and I worked out a fun simple math way of doing it. Definately not the best way, but I thought I'd share it.
You can just use the slope
I'm using an oldx and oldy variable to give me the point just before collision which will simulate force applied to ball. Longer the stride, the harder the ball will be hit.Code:ball.rise = (ball.y - player.oldy) ball.run = (ball.x - player.oldx)
Then its as simple as
Slowing the ball down would be a little trickier, you would have to keep the ratios equal, so use a percentage formula.Code:ball.y = ball.y + ball.rise ball.x = ball.x + ball.run
Just for kicks, vectors would be the best way though, a lot more control and accuracy. This method will cause shakiness in the slowdown. Just thinking outside the box.Code:if ball.rise > 0 then --maintains motion direction ball.oldrise = ball.rise ball.rise = ball.rise - 1 elseif ball.rise < 0 then ball.oldrise = ball.rise ball.rise = ball.rise + 1 end ball.run = math.floor((ball.rise * ball.run) / ball.oldrise) if ball.rise == 0 then ball.rise = 0 ball.run = 0 end
-
04-09-2007, 04:10 PM #6738QJ Gamer Gold
- Registriert seit
- Aug 2006
- Ort
- Under Your Bed
- Beiträge
- 3.083
- Points
- 12.189
- Level
- 72
- Downloads
- 0
- Uploads
- 0
Does anyone know how to get ahold of be2003 the creator of sysext.lrx (I think) Or get his source. I plan on improving the .zip compress and uncompress
-
04-09-2007, 04:31 PM #6739
can i make it like this? i want it like that
Zitat von HaxxBlaster
Timer = Timer.new()
while true do
pad = Controls.read()
if pad:up() then
Timer:start()
end
if Timer:time() >= 10 then --I suggest you put the value 10 higher, because the timer counts in milliseconds.
player.y = player.y - 20
Timer:reset()
end
end
-
04-09-2007, 08:14 PM #6740
lol good job. And even worse, I think you are restarting the timer every loop.
Zitat von HaxxBlaster
BTW, 2 line code:
timer = Timer.new(); timer:start()
screen:blit(player.x,player.y-timer:time()/10,player.img)牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-09-2007, 08:24 PM #6741words are stones in my <3

- Registriert seit
- Jul 2005
- Ort
- Spokane
- Beiträge
- 5.008
- Points
- 35.274
- Level
- 100
- My Mood
-
- Downloads
- 1
- Uploads
- 0
I cant really understand youresam's post, but what he's getting at is you've named a variable the name of a reserved class in Lua.
'Timer' is a reserved class of functions in Lua. Declaring a varaible named Timer will cause errors as you cant assign a class as a value.
Same with 'Music' and 'Sound' and 'screen' i believe...
Correct me if im wrong anywhere above.
...at what speed must I live.. to be able to see you again?...
Projects
You can support my Open World 3D RPG for PSP by voting for it here
-
04-09-2007, 08:32 PM #6742QJ Gamer Bronze
- Registriert seit
- Aug 2006
- Ort
- Washington
- Beiträge
- 759
- Points
- 9.999
- Level
- 66
- Downloads
- 0
- Uploads
- 0
why wont you answer my pm sg57?
also if i have a cube:
how do i make it move forward and left and right?Code:cube = { bla bla bla bal ect ect ect cec lol ol ol ol ol olol }
add speed or lower speed, proper brakes?
or is there any 3d lua tuts out? i searched google and didnt find any
i am making a racing game :O(´・ω・‘)ノシ
-
04-09-2007, 09:07 PM #6743Your Fate is Grim...

- Registriert seit
- Oct 2005
- Beiträge
- 2.269
- Points
- 11.640
- Level
- 70
- Downloads
- 0
- Uploads
- 0
dont take this personally, but if you cant figure out how to move a model, you're quite simply not ready to make even a bad racing game. also, you're not gonna find exact tutorials on every little thing. you need to learn the actual physics of cars, and apply that to your game. however, to asnwer your question:
Zitat von Jomann
you should have a vector of the cars position. like this: (its C, i havent worked with lua in some time)
now, to move it, its simply a matter of changing the coordinates, just as you would in 2D, but with an added dimension. like:Code:ScePspFVector3 carPos = {0, 0, 0}; sceGumLoadIdentity(); sceGumTranslate(carPos); // Draw Car //
also, keep in mind that the above example will not get you anywhere. you will also have to keep a direction vector, and use that to calculate the direction in which the car will move. i recommend reading the articles on gamedev.netCode:if (pressed right) { carPos.x += speed; } etc.--------------------------------------------------------------------------------------
-
04-09-2007, 09:23 PM #6744QJ Gamer Bronze
- Registriert seit
- Aug 2006
- Ort
- Washington
- Beiträge
- 759
- Points
- 9.999
- Level
- 66
- Downloads
- 0
- Uploads
- 0
hey im not dumb :P lol anyway thank you, i knew how to move the model but i didnt understand how to put it in my code thats why i put the cube = {}
thingy up there(´・ω・‘)ノシ
-
04-09-2007, 10:05 PM #6745QJ Gamer Green
- Registriert seit
- Nov 2005
- Ort
- Sweden
- Beiträge
- 460
- Points
- 6.520
- Level
- 52
- Downloads
- 0
- Uploads
- 0
Sure. Is your point to make it move in one direction when you press a button?
Zitat von moncristo_da_dev
Something like this?:
Code:RT = Timer.new() LT = Timer.new() UT = Timer.new() DT = Timer.new() Speed=10 while true do pad = Controls.read() if pad:right() then RT:start() elseif pad:up() then LT:start() end if pad:up() then UT:start() elseif pad:down() then DT:start() end if RT:time() >= 200 then --I suggest you make the value 200 to fit, because the timer counts in milliseconds. player.x = player.x + Speed RT:reset() RT:start() elseif LT:time() >= 200 then --I suggest you make the value 200 to fit, because the timer counts in milliseconds. player.x = player.x - Speed LT:reset() LT:start() end if UT:time() >= 200 then --I suggest you make the value 200 to fit, because the timer counts in milliseconds. player.y = player.y - Speed UT:reset() UT:start() elseif DT:time() >= 200 then --I suggest you make the value 200 to fit, because the timer counts in milliseconds. player.y = player.y + Speed DT:reset() DT:start() end end
I don't think it's what he want to do.
Zitat von youresam
I know, i think it works anyway. I've done it before. I remade the code.
Zitat von SG57
[CENTER]Some of my homebrew Applications/Games:
[URL=http://forums.qj.net/showthread.php?t=47294&page=1&pp=10]Planet Fighter[/URL] | [URL=http://forums.qj.net/showthread.php?p=641672#post641672]Graphic Creator (V2.0)[/URL] | [URL=http://forums.qj.net/showthread.php?p=512717]Fire Pong[/URL] | [B][URL="http://forums.qj.net/f-psp-development-forum-11/t-release-brushes-v20-99207.html#post1430891"][COLOR="Red"][SIZE="3"]Brushes v2.0[/COLOR][/SIZE][/B][/URL] [URL="http://forums.qj.net/f-psp-development-forum-11/t-release-brushes-v20-99207.html"][B][SIZE="2"][COLOR="Black"]Released![/COLOR][/SIZE][/B][/URL]
[URL="http://haxxblaster.2u.se/"][COLOR="black"][FONT="Arial Black"]www.HaxxBlaster.com[/FONT][/COLOR][/URL]
[URL="http://forums.qj.net/f-psp-development-forum-11/t-release-brushes-v20-99207.html"][IMG]http://img19.imageshack.us/img19/1346/brushesbannerqz3.png[/IMG][/URL][/CENTER]
-
04-09-2007, 10:07 PM #6746lol

- Registriert seit
- Aug 2006
- Ort
- Whittier, CA
- Beiträge
- 5.791
- Points
- 20.859
- Level
- 91
- Downloads
- 0
- Uploads
- 0
How do you save a string with non-number elements in it?
-
04-09-2007, 10:22 PM #6747
...you can name any variable anything, except for the programming-specific keywords...but...
Zitat von SG57
Timer = Timer.new()
Do you not see something seriously wrong with that code?!牧来栠摩琠敨映汩獥
PSN: youresamFrom Earth the Frozen Ipaqs shall rise and be silenced and all will live free.
--Mike Hollingsworth
-
04-09-2007, 11:24 PM #6748.info

- Registriert seit
- Jun 2006
- Ort
- ACT, Australia
- Beiträge
- 1.674
- Points
- 15.395
- Level
- 80
- Downloads
- 0
- Uploads
- 0
blah = "blah"
Zitat von Anti-QJ
..
-
04-10-2007, 12:54 AM #6749QJ Gamer Green
- Registriert seit
- Jul 2006
- Ort
- Middle Europe
- Beiträge
- 1.281
- Points
- 11.800
- Level
- 71
- Downloads
- 0
- Uploads
- 0
i have a text file like this:
and now i need with file io save new value to code3, how would i do that??Code:code1 = 0 code2 = 0 code3 = 0 code4 = 0 code5 = 0
[1 Year QJ Member]
[LUA Coder and C Learner]
[Ball Revamped Clone v0.1]
[Phil's Shooting Range v0.3]
[HideFile PRX v2]
[SSR PRX v1.1]
-
04-10-2007, 04:56 AM #6750
im just making a simple jump function
Zitat von HaxxBlaster


LinkBack URL
About LinkBacks
Mit Zitat antworten



Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum