Collision is not detected after setting the positions of the bodies

Software: Away3D 4.x

jellix, Newbie
Posted: 07 March 2014 08:44 AM   Total Posts: 4


when I apply forces onto my “ship on water” and it collides with the land it successfully dispatches a collision event.

But when I place my ship by setting the position manually, a collision with the land won’t be detected.

This works:
_shipBody.applyCentralForce(shipFront); -> Collision can be detected.

This won’t work:
_shipBody.position = _shipBody.position.add(shipFront); -> Ship drives through the land without collision.

Does anybody knows a reason for that?


John Brookes, Moderator
Posted: 07 March 2014 12:24 PM   Total Posts: 732   [ # 1 ]

To move a non static rigidbody you would normally use forces. Thats how the real world works.
What your doing with constantly setting a position is teleportation. It just jumps from its last position.

A collision is happening, but there is no force for the physics to apply to your rigidbody and bounce off the object your hitting.
So it will drive through the object your colliding with.

If you added a collision event to your rigidbody you would see the collision firing.
Look at the in the examples.

What your doing by setting position is making the body move like a kinematic object.
Look at the CharacterDemo to see how to stop the kinematic body if thats what you really want.

Otherwise move stuff with forces and only use position to setup / teleport.


jellix, Newbie
Posted: 07 March 2014 12:51 PM   Total Posts: 4   [ # 2 ]

Hi John,
thanks a lot!

I’d like to tell you my secific needs, and probably there’s another way than to “teleport” my rigid body (I understood your explanations).

I have a ship on water and would like to apply forces to it instead of placing it. But when I rotate the moving ship (e.g. to left), it doesn’t move to the local front direction but to the previous direction that was given through the force.

Because of that I’m placing the ship onEnterFrame relative to it’s local direction.

And I’ve tried to find the code how to stop a character/vehicle but in “CharacterDemo” I don’t see the part where the character stops.


John Brookes, Moderator
Posted: 07 March 2014 02:12 PM   Total Posts: 732   [ # 3 ]

This is where the character is stopped but dont think you need to do this.. Use forces

You should be able to move the rigibody any direction you want with forces.
You just got to get the direction right.

So all mesh and even rigidBodies have a forwardVector ( think its called front with rigidbodies) left right up etc vectors.
mesh.forwardVector = the direction your ship is pointing.

So doing
myForce = myRigibody.front

moves the ship forward whatever direction its pointing.

If you get stuck post a full src file that I can “quickly” load (no assets) and point you in the right direction.


jellix, Newbie
Posted: 07 March 2014 02:43 PM   Total Posts: 4   [ # 4 ]

hmmm ... the problem is the the new force is added onto the existing force instead of replacing it.
Maybe I shouldn’t just rotate the rigibody. Perhaps there is a way to “steer” a RigidBody to left and right ...?

I have the following code within my “onEnterFrame”-handler:

var engine:Number = 0;

if (_shipBody) {
  var shipFront:Vector3D = _shipBody.front;
  if (_keyUp) {
    engine = 1;
  } else if (_keyDown) {
    engine = -1;
  } else {
    //no throttle
  if (_keyLeft) {
    _steering -= _steeringSpeed;
  if (_keyRight) {
    _steering += _steeringSpeed;
  _shipBody.rotation = new Vector3D(0,_steering,0);


John Brookes, Moderator
Posted: 07 March 2014 03:02 PM   Total Posts: 732   [ # 5 ]

You rotate things with torque. Again forces not positions/rotations

Or you could apply a force to the rear of the ship to simulate the rudder.
applyForce instead of central force.

You need to set the opposite forces and possibly clamp the max values. eg the drag of the water. Set damping etc.


jellix, Newbie
Posted: 07 March 2014 03:21 PM   Total Posts: 4   [ # 6 ]

Got that grin

So I should give “impulses” at the front of my ship to get it pushed into a direction.

Just found another solution (maybe not a good one, but it works fine for now):
I have a instance-variable called “shipSpeed” that I increment/decrement onEnterFrame. Then I gave the body a linearDamping of 1. On everyFrame I scale the ships “front” by the shipSpeed and apply it to the body. By that the ship always turns into its local direction.

But your “solution” sounds more plausible. I will try to make it that way.

Many thanks for your help!



Away3D Forum

Member Login