Game Development Community

Creating a player moveable object in mini-platformer tutorial

by Brian Riordan · in Torque Game Builder · 06/24/2009 (5:16 pm) · 2 replies

How would you add an object the player can move by running into it? I tried adding a crate, putting it in the correct collision layer and give it a low mass and friction and setting the collision response to CLAMP. That just stops the player like running into any other fixed object.

I know I can create a collision callback and apply a velocity to the crate when the player collides with it, but can it be done easily with the physics and collision properties.
Thanks,
Brian

#1
06/25/2009 (5:49 am)
I'm not sure how the PSK is coded, but you could, in the onCollision callback, have the %dstObj move with say, half the speed of the player.
#2
06/25/2009 (5:53 am)
function crate::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) {  
   if(getWord(%normal, 0) != 0 && %dstObj.class $= "player") {
      %this.setLinearVelocityX(%dstObj.getLinearVelocityX() / 2);
      %dstObj.setLinearVelocityX(%dst.getLinearVelocityX() / 2);
   }
}