Aniketos
Member
|
Question about addForce, addImpulse, addVel etc
I was testing around with addForce but I had some trouble creating the desired effect.
I basically want to add force from an specific direction. So lets say my character is facing an object and I kick it I want it to fly the opposite direction from my character.
I tried stuff like this: attackTarget->ctrl.actor.addForce(Vec(0,40,40), Vec(Players[0].ctrl_pos));
But it didn't yield the results I wanted.
Also whats the difference between all these:
Actor& addForce (C Vec &force ); // add force , unit = mass * distance / time^2
Actor& addForce (C Vec &force , C Vec &pos); // add force at world 'pos' position, unit = mass * distance / time^2
Actor& addImpulse(C Vec &impulse ); // add impulse , unit = mass * distance / time
Actor& addImpulse(C Vec &impulse, C Vec &pos); // add impulse at world 'pos' position, unit = mass * distance / time
Actor& addVel (C Vec &vel ); // add velocity , unit = distance / time
Actor& addVel (C Vec &vel , C Vec &pos); // add velocity at world 'pos' position, unit = distance / time
Stuff like addForce(Vec &force, vec &pos) seem to result in pretty much the same thing as addForce(Vec &force).
|
|
12-13-2010 07:09 AM |
|
menajev
Member
|
RE: Question about addForce, addImpulse, addVel etc
AFAIR when there is no pos given force is placed in the middle of object.
Try something like addForce(actor.pos-player.pos,player.pos);
|
|
12-13-2010 01:28 PM |
|
Esenthel
Administrator
|
RE: Question about addForce, addImpulse, addVel etc
Check the "game basics/big overlays" it has dynamic explosions and applying forces
|
|
12-13-2010 01:30 PM |
|
Aniketos
Member
|
RE: Question about addForce, addImpulse, addVel etc
I'm probably doing something wrong but something like this doesn't do anything for me.
Vec dir =ctrl.actor.pos()-Players[0].ctrl.actor.pos(); // get difference between actor position and explosion position
Flt dist =dir.normalize(), // normalize direction and store its previous length into 'dist'
dist2=Sqr(dist);
ctrl.actor.addImpulse(30 * dir / dist2); // final equation for impulse = (power) * (normalized direction) / (distance^2)
|
|
12-13-2010 01:52 PM |
|