Box2D Forums

It is currently Wed May 22, 2013 10:18 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Rotating upon collison
PostPosted: Tue May 08, 2012 3:46 pm 
Offline

Joined: Wed May 18, 2011 1:23 pm
Posts: 8
I'm shooting fireballs which have a tail and I want them to rotate when they bounce off objects. I tried to change their rotation on END_CONTACT but it won't let you alter its rotation once it's moving and I read this messes up the events. Now I'm destroying them on collision and recreating new ones that are rotated the correct direction. This mostly works but sometimes crashes my game. I assume there is a much easier way. Anyone have any ideas?


Top
 Profile  
 
PostPosted: Wed May 09, 2012 1:59 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
Does it really matter what rotation the physics body itself has?
Could you just draw the fireball in the appropriate angle based on the current direction of movement?


Top
 Profile  
 
PostPosted: Wed May 09, 2012 8:00 am 
Offline

Joined: Wed May 18, 2011 1:23 pm
Posts: 8
That's what I tried to do. I did fireball.rotation = new trajectory but the engine wouldn't let it work. I can only change the rotation before the object is working in the physics world. Once it's bouncing around, changing the rotation doesn't have any effect. I also read a post by they guy that created Box2d saying that changing the rotation in this way would mess up the events of Box2d. What am I missing?


Top
 Profile  
 
PostPosted: Thu May 10, 2012 2:41 pm 
Offline

Joined: Fri Dec 14, 2007 8:07 pm
Posts: 913
That wont work because WCK sets the rotation of the movieclip each frame to the rotation of the b2body. You actually have to rotate the b2body:
Code:
b2body.SetTransform(b2body.GetPosition(), 60 /* <-- angle */);

If this doesn't work inside of your contact event listener, try changing it after the timestep.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group