Jump to content

How to make a P2 body accelerate along the x-axis?


ChubbRck
 Share

Recommended Posts

Hi all,

 

Trying to make a P2 body accelerate (as opposed to using moveLeft) but am having a tough time, tried to use applyForce like this:

 basket.body.data.applyForce([100,100], basket.x, basket.y);

As well as this..

 basket.body.data.applyForce([100,100], [basket.x, basket.y]);

with no results.  Anyone know what I'm doing wrong? I have tried changing the 100 to a number much larger as well as change gravityScale back to 1 (it is currently at 0).

 

Thanks - 

 

Nick

Link to comment
Share on other sites

Think you need to use the second version. And you also need to do it every frame. Is that what you do?

 

If it does not work, you can always do this (every frame):

basket.body.data.force[0] = 100;basket.body.data.force[1] = 100;

The .applyForce method does this - adds to the force vector.

 

Stefan

Link to comment
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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...