Realistic lobbing of an object
by Michigan State University (#0004 · in Torque Game Builder · 02/13/2008 (3:33 pm) · 4 replies
I am trying to have a grenade be thrown in my game but I am having a problem getting it to react realistically. I need to make it slow down over time or when there is a collision. I have not found any way to do this so far. Any help will be greatly appreciated.
#2
Rofl.
Honestly, games are just illusions. Are we talking about a side view deal or a top down deal or some other kind of deal?
02/14/2008 (7:27 pm)
Quote:Realistic and TGB do not belong in the same sentence =P
Rofl.
Honestly, games are just illusions. Are we talking about a side view deal or a top down deal or some other kind of deal?
#3
tdn.garagegames.com/wiki/TGB/MiniTutorials/BallPhysics
tdn.garagegames.com/wiki/T2D/FAQ/Bouncing_ball_physics
02/15/2008 (4:01 am)
You could also try rigid body physics. It is pretty poorly documented but following links might help:tdn.garagegames.com/wiki/TGB/MiniTutorials/BallPhysics
tdn.garagegames.com/wiki/T2D/FAQ/Bouncing_ball_physics
#4
Shoot it off at an upward angle with setLinearVelocityPolar(), then enable the onUpdateCallback.
In the grenade::onUpdate do
grenade.setLinearVelocity(t2dVectorAdd(grenade.getLinearVelocity(), $gravity));
Where $gravity is something like "0 10" or any suitable Y value to make it fall.
That's for a grenade falling in an arc in a side view 2D game. If you're doing a top-down game and you just want the grenade to slow down, use this in the onUpdate callback:
grenade.setLinearVelocityPolar(%angle, getWord(grenade.getLinearVelocityPolar(), 1) - %drag);
Where %angle is the angle the grenade was thrown, and %drag is some suitable value to slow it down.
When there's a collision you could use the %normal from the onCollision callback to bounce the grenade away at that vector with
grenade.setLinearVelocity(t2dVectorScale(%normal, %bounceStrength);
where %bounceStrength is the bounciness of the grenade.
02/17/2008 (11:17 pm)
Don't use torque's physics at all, turn it off on the grenade object, but leave collision on.Shoot it off at an upward angle with setLinearVelocityPolar(), then enable the onUpdateCallback.
In the grenade::onUpdate do
grenade.setLinearVelocity(t2dVectorAdd(grenade.getLinearVelocity(), $gravity));
Where $gravity is something like "0 10" or any suitable Y value to make it fall.
That's for a grenade falling in an arc in a side view 2D game. If you're doing a top-down game and you just want the grenade to slow down, use this in the onUpdate callback:
grenade.setLinearVelocityPolar(%angle, getWord(grenade.getLinearVelocityPolar(), 1) - %drag);
Where %angle is the angle the grenade was thrown, and %drag is some suitable value to slow it down.
When there's a collision you could use the %normal from the onCollision callback to bounce the grenade away at that vector with
grenade.setLinearVelocity(t2dVectorScale(%normal, %bounceStrength);
where %bounceStrength is the bounciness of the grenade.
Associate Phillip O'Shea
Violent Tulip
I think the first thing you should look at is setting the mass of the grenade manually and then set the collision response mode to bounce. This should let it bounce off the ground and giving it a large weight should make sure it doesn't bounce high.
Give that a go and if that doesn't work I will try to think of something else.