About Store Forum Documentation Contact



Post Reply 
Question about addForce, addImpulse, addVel etc
Author Message
Aniketos Offline
Member

Post: #1
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
Visit this user's website Find all posts by this user Quote this message in a reply
menajev Offline
Member

Post: #2
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
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
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
Find all posts by this user Quote this message in a reply
Aniketos Offline
Member

Post: #4
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
Visit this user's website Find all posts by this user Quote this message in a reply
Aniketos Offline
Member

Post: #5
RE: Question about addForce, addImpulse, addVel etc
Kind of late reply but tnx I got it working smile
12-17-2010 12:30 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply