Game Development Community

need help applying impulse

by deepscratch · in Torque 3D Professional · 02/26/2011 (9:02 pm) · 7 replies

hi all,

a slightly tricky one this,
perhaps you have an idea,

I have set up throwing an object,
this object, when thrown, has velocity, momentum, mass, and a vector.
this is NOT a physics object,
this object does, however, respond to impulses.

when this object hits the terrain, it stops dead, this is correct, it has no physics,

but.....

it has velocity, momentum, mass, and a vector....

I can get the objects transform when it hits the terrain "(object Transform is -703.845 685.125 62.4177 -0.0434806 0.950748 0.306901 0.95884)"

I can get the collision point where it hits the terrain "onImpact(objName, objClass, terrain, -1.11968 -3.22551 4.80702, 5.89619)"

now...

I need to create a "bounce" effect function, a single impulse to the object, that takes the obj transform and point of impact, and gives it the equal but opposite impulse.

think of a stone in space hitting an asteroid, an impact, an impulse, then off into space in a straight line, on the projected course, thats kind of exactly what I need to achieve.

please,
any help or thoughts on how to do this would be great,
I was thinking a script function that could get called by onImpact?

I just have no clue where to start with this...:(

thanks.

#1
02/27/2011 (1:23 am)
You have to calculate a reflection vector,take a look at the debris code.
#2
02/27/2011 (10:03 pm)
Did you tell Sulu "Ahead full impulse?"
#3
02/28/2011 (11:11 am)
Quote:
I have set up throwing an object,
this object, when thrown, has velocity, momentum, mass, and a vector.
this is NOT a physics object,
this object does, however, respond to impulses.
Granted you said "NOT a physics object", but have you tried using a RigidShape in place of your custom? object - since you mention wanting it to bounce.
#4
02/28/2011 (4:56 pm)
cant u apply Pzones to any object?
#5
02/28/2011 (5:25 pm)
What about spawning it as a projectile. They you can set it up to be ballistic and it supports bouncing.
#6
03/01/2011 (6:36 am)
@Ivan,
I thought about Debris, but Debris just has too much extra stuff for my needs. it truely is a reflection vector I need.

@Richard,
yes, but Spock couldn't find logic in that, and Scotty couldn't give it any more power ;(

@Michael,
at first it was a RigidShape, but it did not suit.

@Ryan,
wouldn't work, it needs to be in game for a long time, must not apply damage, and actualy must not bounce....

let me explain better,

a ray of light hits a mirror at a certain angle, that ray goes off in the equal but opposite angle, basic trigonometry,
the ray does not "bounce", gravity does not effect it, and it will keep going straight, till it hits another mirror, then will repeat its exercise again.

my math really sucks, but I've seen things like "MathUtils::createOrientFromDir" which sounds like a candidate for a source solution? but script would be better.

more ideas?
#7
03/01/2011 (7:31 am)
You could give the projectile a long lifespan and arming delay with zeros for damage values. When it calls the explode callback just replace it with an item if you want it to hang out longer. But here is the bounce code from projectile that contains what I think your looking for, just take the parts you need.
if ( mDataBlock->isBallistic )
         {
            // Otherwise, this represents a bounce.  First, reflect our velocity
            //  around the normal...
            Point3F bounceVel = mCurrVelocity - rInfo.normal * (mDot( mCurrVelocity, rInfo.normal ) * 2.0);
            mCurrVelocity = bounceVel;

            // Add in surface friction...
            Point3F tangent = bounceVel - rInfo.normal * mDot(bounceVel, rInfo.normal);
            mCurrVelocity  -= tangent * mDataBlock->bounceFriction;

            // Now, take elasticity into account for modulating the speed of the grenade
            mCurrVelocity *= mDataBlock->bounceElasticity;

            // Set the new position to the impact and the bounce
            // will apply on the next frame.
            //F32 timeLeft = 1.0f - rInfo.t;
            newPosition = oldPosition = rInfo.point + rInfo.normal * 0.05f;
         }