xephyros Posted November 20, 2014 Share Posted November 20, 2014 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! Quote Link to comment Share on other sites More sharing options...
xephyros Posted November 21, 2014 Author Share Posted November 21, 2014 Sorry, solved it, forgot that I'd kept the object 2's mass at the max number value when should in this case keep it as a static body. Is there a cleaner way to do this? 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.