Game Development Community

Player Collision Issues

by Dylan Dawson · in Torque 3D Beginner · 02/26/2014 (12:04 pm) · 5 replies

Hi all, I'm relatively new to torque. I am creating a game that involves a ball shaped player model. My main problem is that my model is not colliding with the terrain properly. It appears to only collide with the origin of the ball (Center). I'm assuming this has something to do with collision boxes. I attempted to edit the collision box in my code with no success. The ball has a 0.5 unit radius, and the default collision box is "1 1 1" which should encompass it. Any help would be appreciated.

Collision Image: http://imgur.com/saqIyNI


singleton Material(PlayerMaterial)
{
   diffuseMap = "art/shapes/player/SoccerBall_MAT";
   mapTo = "Platonic";
};

datablock PlayerData(DefaultPlayerData)
{
   shapeFile = "art/shapes/player/SoccerBall.dae";
   cameraMaxDist = 5;
   
   jumpForce = 10;
   jumpDelay = 1;
   maxForwardSpeed = 10;
   maxBackwardSpeed = 8;
   maxSideSpeed = 8;
      
   mass = 1;
   density = 1;
   
   updateRate = 100; // How many updates per second
   lastPos = 0;
};

About the author

Recent Threads


#1
02/26/2014 (12:27 pm)
When you're in the world editor you can click on the little eye icon up the top to the right of camera speed and it allows you to enable debug render modes. In this case what you'll want to turn on Debug Render: Bounding Box and it'll show you the bounding boxes so you can identify the problem.

If I had to take a guess though I would say your model was centered when you imported it. Shape base builds the building box from the origin up as far as I know so flooring the model on import should correct the issue.
#2
02/26/2014 (3:05 pm)
Thank you for the fast help, I re-exported the model from blender with the origin at the bottom and it fixed it. However is there a manual way to define the starting position of a Bounding Box from Script? Better yet is there a way to set the bounding box of the player model to be round for more accurate collision?
#3
02/27/2014 (3:21 pm)
I would of thought using the Visible Mesh for your boundary would work but I've only ever used it on static objects not 100% sure if it's available for the player but i'm sure it is
#4
02/28/2014 (6:21 pm)
Players (default setup) uses a special collision system combined
with the Physics system..

Player.cpp
// size of bounding box
   boxSize.set(1.0f, 1.0f, 2.3f);
   crouchBoxSize.set(1.0f, 1.0f, 2.0f);
   proneBoxSize.set(1.0f, 2.3f, 1.0f);
   swimBoxSize.set(1.0f, 2.3f, 1.0f);

   // location of head, torso, legs
   boxHeadPercentage = 0.85f;
   boxTorsoPercentage = 0.55f;

which is set here: [player datablock]
boundingBox = "0.5 0.5 1.75";
   crouchBoundingBox = "0.65 0.75 1.3";
   swimBoundingBox = "1 2 2";
   pickupRadius = 1;

I've never attempted to convert it to visible mesh and not even sure
where you would start *hehe*
Exporting your character is always an issue if not done properly and
then you need to adjust these values to get them as close to the size
of your ball..

boxSize.set(...) --> boundingBox = "X Y Z"

you will be able to ignore the others.

Converting to a Ball shape, would probably require making a new
version of the Player Class that uses the standard collision systems.
#5
02/28/2014 (6:28 pm)
I have a ball shaped character. I suggest using physX for this. I had to make my own ball class (sorry not releasing source code). But yeah I strongly suggest not using the player class. Just make a new class off of ShapeBase and hook it up with a spherical collision mesh. Then you can apply forces and torques to it to make it move/roll.

If that will be your new "player" class, make sure you hook up a way to have movement applied, which is in the ProcessTicks method defined in shapebase. That passes a Move object to it which allows you to grab the player input. It is called in a fixed 32ms time stamp. From there, apply your forces and torques to make it move. Also you'll need to come up with a camera code, see the player.cpp for camera and movement code.