anup Posted November 12, 2013 Share Posted November 12, 2013 Hi Team, I am developing an app using cocos2d game engine. I am using box2d as physics engine. I want to move a particle when on clicked will show a predecitve projectile path and when released the object should move in the same path as the predected motion.(This requirement resembles angry birds game). Please help if anyone is aware of how to achieve this. I am attaching a sample project where the bird is launced but the projected motion is not show in the current project.Please help on the same. Thanks and Regards,Anupsimpleangrybirds.zip Quote Link to comment Share on other sites More sharing options...
BigRob154 Posted November 13, 2013 Share Posted November 13, 2013 iforce has some nice tutorials for Box2D.There is also a tutorial for projected trajectory. It's in C but the same principles apply for JavaScript as well. http://www.iforce2d.net/b2dtut/projected-trajectory Quote Link to comment Share on other sites More sharing options...
anup Posted November 13, 2013 Author Share Posted November 13, 2013 Thanks for the concern, but i wanted something in javascript. As i am a newbie completely to this I faced some difficulty while porting code from C to JS. This finally led to no result. So please suggest. Quote Link to comment Share on other sites More sharing options...
Psychho Posted November 13, 2013 Share Posted November 13, 2013 How to launch a body towards the mouse cursorvar bodyVelocity = body.GetLinearVelocity();//grab the bodys velocityvar launchDirection = body.GetPosition();//grab the bodys position to calculate launch directionlaunchDirection.Subtract(mousePositionWorld.x,mousePositionWorld.y);//subtract the mouse position in box2d space from body position to get the launch direction vectorlaunchDirection.Normalize();//normalize the launch direction so its consistent no matter how far the mouse is from the bodybodyVelocity.SetV(launchDirection);//set the bodys velocity to the launch direction Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.