Jump to content

Update object 2 position with object 1 position p2.js


xephyros
 Share

Recommended Posts

Hey guys and gals,

 

So I'm creating an AI (using p2.js) and want to update its position (vertical only) using another object's position (only getting the vertical position).

 

I have this code here (which is in object 1's update update function): 

game.scene.<object2>.body.position[1] = game.scene.<object 1>.body.position[1];
Which works, but, when either object collides with something, object 2 dissapears and it appears that object 1 goes straight through it (where previously it hit it and bounced off). The restitution and mass of the other objects are 1 and the max number possible respectively, as is object 2.
 
Previously I had been setting an initial speed for object 1 to move at (as a global variable in the objects.js class) and then using that same value for object 2, and it worked, but it didn't update naturally (object 1 moves in both x and y axis, whereas object 1 only moves in the y axis).
 
This ai is the last piece in the puzzle to completing the game and its rediculously frustrating hitting my head against the table repeatedly to make it work!
 
Any help would be much appreciated!
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...