Cancel all movement

Software: Away3D 4.x

J. Neerhof, Newbie
Posted: 16 May 2012 11:46 AM   Total Posts: 8

Hi,

I’m creating a game which uses a ball that’s being shot at a target.
After a shot the ball should go back to the startingposition and must be ready to shoot again.

I use this code to reset the ball:

ballBody.activationState AWPCollisionObject.WANTS_DEACTIVATION;
ballBody.position startPosition

This doesn’t work as I had hoped. it works most of the time, but sometimes the ball gets moved back to the startposition, but then the ball continues to bounce in exactly the same direction as it was going before the transfer to the startposition.
My guess is that the movementspeed and direction somehow isn’t removed and continue to apply to the ball when reset to the startposition.

I thought my code above was a way to deactivate all forces, but appearently not.
So is there a way to completely remove all forces that are being applied to the ball?

 

   

John Brookes, Moderator
Posted: 16 May 2012 12:15 PM   Total Posts: 732   [ # 1 ]

Set angular and linear velocity to zero and reset the rigidbodies position and rotation.

   

J. Neerhof, Newbie
Posted: 22 May 2012 02:30 PM   Total Posts: 8   [ # 2 ]

Hi John,

Thanks for your anwser. It indeed solves (half) the problem.
But somehow the ball still doesn’t react as it should.

The ball is fired a bit to high as it should. And sometimes the ball just rolls away from the starting point or it bounces once and keeps floating above the startposition.

Are there other factors that have to be reset?

   

John Brookes, Moderator
Posted: 22 May 2012 03:57 PM   Total Posts: 732   [ # 3 ]

Could also try clearForces()
If that doesnt work post your code.

   

J. Neerhof, Newbie
Posted: 04 June 2012 01:47 PM   Total Posts: 8   [ # 4 ]

Thanks John,

I fixed the problem thanks to your replies and finished the game.
It’s not online right now, but I’ll post a link to it when it’s ready.

Thanks again!

Regards,

Jochem

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X