Making "Jump pads" and "sliding corpses
by Marc Sandoval · in Torque Game Engine · 12/28/2006 (11:36 am) · 4 replies
You know what are jump-pads. Don't you? Yeah, just like this:
[img]http://fps.brainerd.net/images/launchtut/launch2.jpg[/img]
What I want is a "shape" that catapults some classes (like players) in a given direction and angle. The rigid body physics in Torque will do the rest, but how do apply that force to the Player? That's my first question.
The second one is about "sliding corpses". Yes, when running players die in my game, they just stop and die in the same place. That's not quite realistic, I want their bodies to fall and slide or roll a bit over the floor. That could be done by lowering the Friction parameter on the fly, I guess. But if I recall well, that's impossible without making some workarounds. Any ideas?
Greets and Thanks in advance.
[img]http://fps.brainerd.net/images/launchtut/launch2.jpg[/img]
What I want is a "shape" that catapults some classes (like players) in a given direction and angle. The rigid body physics in Torque will do the rest, but how do apply that force to the Player? That's my first question.
The second one is about "sliding corpses". Yes, when running players die in my game, they just stop and die in the same place. That's not quite realistic, I want their bodies to fall and slide or roll a bit over the floor. That could be done by lowering the Friction parameter on the fly, I guess. But if I recall well, that's impossible without making some workarounds. Any ideas?
Greets and Thanks in advance.
About the author
#2
You get the jist I hope.
12/28/2006 (1:21 pm)
You could just write a collision function for the jump pad..function JumpPad::onCollision(%this, %obj, %colObj)
{
if ( %colObj.getClassName() $= "Player" )
{
%dir = %colObj.getEyeVector();
%norm = VectorNormalize(%dir);
%vec = VectorAdd(%norm, %norm);
%colObj.applyImpulse(%colObj.position, VectorScale(%vec, %colObj.getDatablock().mass * 19));
%colObj.playAudio(0, JumpPadSound);
}
}You get the jist I hope.
#3
12/28/2006 (2:06 pm)
Why not use a physical zone thingy?
#4
12/28/2006 (2:30 pm)
Physical zones can work too but is actually more controlled if you apply impulses, far as direction goes. You can also use setVelocity on player objects. It's really a good idea to try all 3 and pick the one that meets your needs best. Thanks for bringing that up Allyn.
Torque 3D Owner Caylo Gypsyblood
Locate this inside your player.cs file, at the ::onImpact() function (near the end of the file), after you fiddle with this, you should learn how to get what you wish for your own use.
.... ::onImpact(%this, %obj, %collidedObject, %vec, %vecLen) { // lets try and BOUNCE OFF what we just hit... // Also lets not bounce off the ground.... !$= "TerrainBlock") // also lets not bounce away from things we PUSH !$= "RigidShape" // one can check %collidedObject to controle WHAT collidedObject it is.. %HITCLASS = %collidedObject.getclassname(); %HITOBJ = %collidedObject; //%HITSPEED = %vecLen //%HITHURT = %vecLen* %this.speedDamageScale if ( %vecLen < 5 ) return; // Lets not bother thinking about the little BUMPS- do nothing... // lets also NOT do any of this for the following CLASS if ( %HITCLASS $= "TerrainBlock" ) return; if ( %HITCLASS $= "RigidShape" ) return; if ( %HITCLASS $= "Player") return; //Figure in a BOUNCE OFF direction %bounceBack= -2500 ; // How much to bounce away * %vecLen %dir = %obj.getForwardVector(); %position = getWords(%obj.getTransform(), 0, 2); %x1 = getWord(%dir, 0) * %bounceBack; %y1 = getWord(%dir, 1) * %bounceBack; %z1 = getWord(%dir, 2) * %bounceBack; %impulseVec = %x1 SPC %y1 SPC %z1; %obj.applyImpulse(%position, %impulseVec); // Finaly let us HURT the player for running into something hard. // %obj.damage(0, VectorAdd(%obj.getPosition(),%vec), %vecLen * %this.speedDamageScale, "Impact"); }