Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Controlling the Steering of a Vehicle Using Physics - Help Request

Author
Message
JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 27th Sep 2011 20:31
Hello All,

Having trouble understanding how to control the steering of a vehicle using the physics commands. In this case, a Tank.

I know that Kevin Summers did exactly what I need to with his Ludum Dare entry, but I can't seem to be able to wrap my head around how he did it. I can move the Tank without a problem, but when it comes to turning it, that is where I am stuck. Kevin said that he used some Math for the turns, but I don't see any code showing this.

So with all that said, can anyone shed some light on how to control a vehicle, especially during turning?

I've tried several different methods, but the sprite either spins too much or not enough and then continues on the trajectory it was already on, without changing direction. I realize that I need to change the direction of the Force/Impulse/Whatever to match the new angle, but my head hurts trying to figure it out.

I was able to move the vehicles and turn them easily without using physics, but collision detection is much better with physics, so I would prefer going this route.

Any help would be appreciated.

Thanks,
JHA
JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 28th Sep 2011 16:38
Ok, I guess I'm asking too much.

Is there a straight forward web site where I can learn about 2D Physics, related to programming?

I'll Google it, but I just didn't know if anyone knew of a good one.

Thank you,
JHA
ElijahNomad
13
Years of Service
User Offline
Joined: 19th Sep 2011
Location:
Posted: 28th Sep 2011 17:09
Well App Game Kit uses Box2D so in essence checking out the manual http://www.box2d.org/manual.html is going to be a good start. Also, posting some code is going to get you a lot more help.
JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 28th Sep 2011 17:30 Edited at: 28th Sep 2011 17:36
Thanks ElijahNomad!

I didn't know about the Box2D manual. That should help alot.

My code is in a bit of disarray while trying to figure out what each command does, so I'm not sure it would help, but here it is:



I have attached the 2 images I'm using for my test program, which is just a portion of my main program, so I can get a hold of the physics before implementing it.

Here is what I am trying to do, at the moment:

Up Arrow: Move Tank Forward according to the angle it is heading.
Down Arrow: Stop
Left Arrow: Turn Left and if in motion, keep moving in the new direction.
Right Arrow: Turn Right and if in motion, keep moving in the new direction.

If the tank is not current moving, then I need it to just rotate in place.

I guess I just need to know how to calculate the new direction of the tank and change the Impulse / Force to the new direction. I want the change in Velocity to be immediate and not have any acceleration. Maybe I don't need Impulse or Force at all and should just use the Velocity commands ....

Thanks for the help!

JHA

Attachments

Login to view attachments
JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 28th Sep 2011 19:11 Edited at: 28th Sep 2011 19:15
I got it sorted out using just the Velocity commands!!

Here is the full working version as well as an updated Tank image, due to the need for animation for the different directions.



I hope someone will find it useful!!

Thanks,
JHA

Attachments

Login to view attachments
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 28th Sep 2011 19:12 Edited at: 28th Sep 2011 19:13
IRL, when you stopped power to the tracks, your tank would stop moving because of the friction between the ground and the tank. If you are doing a "top down" sprite version, then you can use damping to simulate this. When you press a key you can add the force, when the key is released, damping will stop the movement.

As far as direction, you'll probably need to calculate this, I'm not the best at that, but I can probably find the formulas.

EDIT: Glad you fixed it!

JHA
20
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 28th Sep 2011 19:26
Thanks Rich. That was the approach I was trying to get working with spotty success. The above version does not use any of that, which is really what I was trying to do anyway. All I wanted from the Physics engine was the Collision ability, for this project.

I'll have a go at those functions in a future project though. I definitely want to nail them down.

Login to post a reply

Server time is: 2024-11-22 05:38:08
Your offset time is: 2024-11-22 05:38:08