[JAVA2D] Acceleration and movement problem
I'm trying to make a game with a space ship that has the same physics as the Asteroids ship. you can rotate the ship and accelerate towards the direction the ship is pointing and no air resistance to slow the ship down. If you want to stop, you need to accelerate in the opposite direction of your movement. Anyway, everything works ok except for one thing: I don't have a max_velocity value. That is, i haven't coded a speed limit for the ship. Why I haven't done that is because I don't know how. The game is 2D and programmed in Java using Jogl. A textured polygon is the ship and I rotate it using glrotatef(). I have a vel_x and a vel_y value which keeps track of the velocity of the ship on each axis. I also have a variable angle, which keeps track of where the ship is pointing so I know in which direction to accelerate the ship when the user presses the up-arrow. Anyone have any clue how I can implement a speed limit? Thanx a lot === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] Acceleration and movement problem
You might want to ask this on javagaming.org forums, since it's not a Java2D-specific question: http://www.javagaming.org/cgi-bin/JGNetForums/YaBB.cgi#JavaDevelopment Thanks, Dmitri On Wed, May 11, 2005 at 11:00:32AM -0600, Flavius Alecu wrote: I'm trying to make a game with a space ship that has the same physics as the Asteroids ship. you can rotate the ship and accelerate towards the direction the ship is pointing and no air resistance to slow the ship down. If you want to stop, you need to accelerate in the opposite direction of your movement. Anyway, everything works ok except for one thing: I don't have a max_velocity value. That is, i haven't coded a speed limit for the ship. Why I haven't done that is because I don't know how. The game is 2D and programmed in Java using Jogl. A textured polygon is the ship and I rotate it using glrotatef(). I have a vel_x and a vel_y value which keeps track of the velocity of the ship on each axis. I also have a variable angle, which keeps track of where the ship is pointing so I know in which direction to accelerate the ship when the user presses the up-arrow. Anyone have any clue how I can implement a speed limit? Thanx a lot === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] Acceleration and movement problem
This isn't quite the proper forum to ask about that, but I do have an answer. Your velocity is equal to the absolute value of (vel_x * vel_y), so calculate what vel_x and vel_y are. Then test to see if they are over max_velocity. If they are scale them back down to fix within max_velocity. float velocity = Math.abs(vel_x * vel_y); if (velocity max_velocity) { vel_x *= max_velocity / velocity; vel_y *= max_velocity / velocity; } I think this code will work. I didn't test it. Donovan Boden -Original Message- From: Discussion list for Java 2D API [mailto:[EMAIL PROTECTED] On Behalf Of Flavius Alecu Sent: Wednesday, May 11, 2005 1:01 PM To: [EMAIL PROTECTED] Subject: [JAVA2D] Acceleration and movement problem I'm trying to make a game with a space ship that has the same physics as the Asteroids ship. you can rotate the ship and accelerate towards the direction the ship is pointing and no air resistance to slow the ship down. If you want to stop, you need to accelerate in the opposite direction of your movement. Anyway, everything works ok except for one thing: I don't have a max_velocity value. That is, i haven't coded a speed limit for the ship. Why I haven't done that is because I don't know how. The game is 2D and programmed in Java using Jogl. A textured polygon is the ship and I rotate it using glrotatef(). I have a vel_x and a vel_y value which keeps track of the velocity of the ship on each axis. I also have a variable angle, which keeps track of where the ship is pointing so I know in which direction to accelerate the ship when the user presses the up-arrow. Anyone have any clue how I can implement a speed limit? Thanx a lot === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] Acceleration and movement problem
I think that velocity be Math.sqrt(vel_x*vel_x + vel_y*vel_y). This is the length of the vector (vel_x, vel_y). The rest of the code looks right to me. Dan Boden, Donovan wrote: This isn't quite the proper forum to ask about that, but I do have an answer. Your velocity is equal to the absolute value of (vel_x * vel_y), so calculate what vel_x and vel_y are. Then test to see if they are over max_velocity. If they are scale them back down to fix within max_velocity. float velocity = Math.abs(vel_x * vel_y); if (velocity max_velocity) { vel_x *= max_velocity / velocity; vel_y *= max_velocity / velocity; } I think this code will work. I didn't test it. Donovan Boden -Original Message- From: Discussion list for Java 2D API [mailto:[EMAIL PROTECTED] On Behalf Of Flavius Alecu Sent: Wednesday, May 11, 2005 1:01 PM To: [EMAIL PROTECTED] Subject: [JAVA2D] Acceleration and movement problem I'm trying to make a game with a space ship that has the same physics as the Asteroids ship. you can rotate the ship and accelerate towards the direction the ship is pointing and no air resistance to slow the ship down. If you want to stop, you need to accelerate in the opposite direction of your movement. Anyway, everything works ok except for one thing: I don't have a max_velocity value. That is, i haven't coded a speed limit for the ship. Why I haven't done that is because I don't know how. The game is 2D and programmed in Java using Jogl. A textured polygon is the ship and I rotate it using glrotatef(). I have a vel_x and a vel_y value which keeps track of the velocity of the ship on each axis. I also have a variable angle, which keeps track of where the ship is pointing so I know in which direction to accelerate the ship when the user presses the up-arrow. Anyone have any clue how I can implement a speed limit? Thanx a lot === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help. === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.
Re: [JAVA2D] Acceleration and movement problem
I'm trying to make a game with a space ship that has the same physics as the Asteroids ship. you can rotate the ship and accelerate towards the direction the ship is pointing and no air resistance to slow the ship down. If you want to stop, you need to accelerate in the opposite direction of your movement. Anyway, everything works ok except for one thing: I don't have a max_velocity value. That is, i haven't coded a speed limit for the ship. Why I haven't done that is because I don't know how. The game is 2D and programmed in Java using Jogl. A textured polygon is the ship and I rotate it using glrotatef(). I have a vel_x and a vel_y value which keeps track of the velocity of the ship on each axis. I also have a variable angle, which keeps track of where the ship is pointing so I know in which direction to accelerate the ship when the user presses the up-arrow. Anyone have any clue how I can implement a speed limit? Thanx a lot Again, as others have pointed out, this might be OT for this forum - as might be my response as well - but I just thought I'd quickly mention a resource I came upon that looked interesting that might give you the answer to this. When browsing through the tech section of a bookstore a while ago I remember stumbling onto a book that looked interesting. It was called Physics for Game Programmers (or something similar - you can search Amazon for it if I've got the title wrong). Not sure if it covered exactly this specific problem, but since you say you're creating a game, you might find it helpful for other aspects of your work as well. HTH, DR == This message is for the sole use of the intended recipient. If you received this message in error please delete it and notify us. If this message was misdirected, CSFB does not waive any confidentiality or privilege. CSFB retains and monitors electronic communications sent through its network. Instructions transmitted over this system are not binding on CSFB until they are confirmed by us. Message transmission is not guaranteed to be secure. == === To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to [EMAIL PROTECTED] and include in the body of the message help.