Game Development Community

Impulses on objects directed from the player...

by Max Thomas · in Torque Game Engine · 12/09/2004 (8:35 am) · 18 replies

Hello all,


I am supposed to be doing my math homework at the moment but this seems more important to me at the moment. Ok, so I've been trying to get the player to apply impulses to the objects that it runs into. Say, a box, barrel, table a other player for that matter. I've been trying to modify the onCollision datablock to no avail. I don't really want it to jet flung across the room as though the player kicked it though I want it to seem like it is just pushing it along.

Thanks, Max :)

#1
12/09/2004 (11:35 am)
Ironically, your math homework would be the single thing most likely to prepare you to solve this problem. :)
#2
12/09/2004 (12:23 pm)
Lol

Yup, I would think that it would but It doesn't really want to work that way.

Max :)
#3
12/10/2004 (1:10 am)
The player class has an applyImpulse method. You may have to expose it to script though. Also, everytime a player gets collided with, his onCollision function gets called, and the collider gets passed in. You could put some calls in there to applyImpulse maybe.
#4
12/10/2004 (6:28 am)
Hello,

I allready figured out that I need to put a function in the onCollision data block. I just can't find a call that will work correctly.

Max
#5
12/10/2004 (6:31 am)
Hmm applyImpulse method ? will have to look that one up... any ideas on exposing that to script ?
#6
12/10/2004 (9:05 am)
It already is exposed...
#7
12/10/2004 (9:09 am)
Ya, take a look in radiusDamage.cs to see how applyImpulse works.
#8
12/10/2004 (10:39 am)
I've looked through all the scripts and at every thing to do with impulses and I've tried lots of ways to implament them to no avail. Can someone post a line of code that I could use to get this working please?

Thanks, Max :)
#9
12/19/2004 (8:51 pm)
This is pretty much straight from radiusDamage.cs, but to make it more clear:

%obj is the object you want to move

// get the player location
%playerPosition = %player.getTransform();

// get the direction from the player's position to the object's center
%impulseVec = VectorSub(%obj.getWorldBoxCenter(), %position);
// only want the direction, not the distance
%impulseVec = VectorNormalize(%impulseVec);

// scale the vector to represent force of the impulse (in the direction of the target)
%impulseVec = VectorScale(%impulseVec, 10);

// apply the force along the vector from player to object
%obj.applyImpulse(%playerPosition, %impulseVec);


radiusdamage.cs is a little more sophisticated in that it scales down the force based on distance so that a distant object is not affected but closer objects get more force applied. If it were applied to player movement, a constant impulse force should be fine (I'm making the assumption that the engine handles some kind of mass calculations with this so that applying a constant impulse regardless of object size would have less effect on more massive objects?).

Russ
#10
12/26/2004 (10:13 pm)
Hello Russ,

THis is still really bugging me I've tried a variety of ways and things but still no luck. I've even tried a few other code snippets that people have posted elsewhere and they havn't worked... Can you please help, Sorry for all your time.

Thanks, Max
#11
12/27/2004 (8:13 am)
What sort of object are you applying an impulse to? If it's a static shape then it could be a problem. Those aren't supposed to move...

(static means nonmoving)
#12
12/27/2004 (10:49 am)
Lol, "static means nonmoving" I know that I'm not super daft.

I'm trying to apply a impulse to to wheeled vehicles when the player runs into them, I know it sould's wierd.

Thanks, Max
#13
12/27/2004 (11:27 am)
Not too weird, interesting :)
#14
12/27/2004 (4:17 pm)
Can anyone please post a code snippit or summit I'm desperate!

THanks, Max :)
#15
12/28/2004 (3:04 am)
Check out the onThrow call. The player impulses items.
#16
01/16/2005 (3:12 pm)
Hey,

Just got back to this same problem once again. I tried using the onThrow call Todd but to no avail, moved the impulse code from a weapon to the player and still nuthin, any idea's?

Max
#17
02/10/2005 (10:43 am)
I think you could mod this resource to work for you.

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2302

I would try step 3 with your players onCollision and see if that works.

I have not tried to mess with moving objects with this method but will need to do that soon. I will mess with it and see if I get it working but if anyone else already knows what I would have to do to make objects react to explosions please let me know. I do have a few Ideas on how I will get it to work I am just busy on some other aspects of our game right now.

hope that helps
#18
02/10/2005 (12:28 pm)
Hey Matt,

Thanks for that, I actually just recently figured out how to do that. If you like I can paste the little block of code I used. What do you mean by objects reacting to explosions?... Like shooting a rocket and having a barrel get affected by the explosion and get fired away?... I can help you with that if ya like I managed to do so a while back if thats what you mean.

THanks, Max :)