Sign in to follow this  

Simple P2 Question

Recommended Posts

Here's my question.


I want to make a P2 body move in the direction it is already pointing.


I tried moveUp(), moveDown(), etc. but they (not surprisingly) only go up or down.


I tried thrust() but it does not seem to work unless it is being applied repeatedly.. as in the Update section.


Just for the heck of it I tried this....


for (var i = 0; i < 500; i++)        mysprite.body.thrust(500);
and it did what I want, but I feel that this is probably not the way I should do this.
Is there a better way?

Share this post

Link to post
Share on other sites

Sorry, I should have read your questions more closely. From what I've seen in the examples, you need extract the body's direction (i.e., rotation) and apply XY explicitly. E.g., for constant velocity:

bug.body.velocity.x = Math.cos(bug.rotation) * BUG_SPEED;bug.body.velocity.y = Math.sin(bug.rotation) * BUG_SPEED;

To accelerate, there's a good example here Below's a snippet:

obj1.body.force.x = Math.cos(angle) * speed;    // accelerateToObject obj1.body.force.y = Math.sin(angle) * speed;

Share this post

Link to post
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.