I want this display object being the player TO BE LOCKED on the Y axis so when other physics bodies collide with the player the player will not be moved, but the player needs to be able to move freely on the x axis.
You could create a piston joint between a static object somewhere just off-screen and the player object. The joint would be oriented from left to right. Be aware that if other objects collide with it it might get pushed away from the axis, but test it out.
Maybe I’m not understanding what you want to do, but can you set isSensor=true on the player so physics collisions don’t push it at all?
Jay
oh dang that would’ve worked but I figured out a different way to fix it thanks though!
I would have added an enterframe listener with a object.y = yOrigin (where yOrigin is the Y you want).
How did you fix the problem ? Maybe this could help someone in the same case.
I wouldn’t do that if I were you. It is directly fighting the Box2D physics engine and will eventually cause catastrophic problems in your code. One situation I’ve seen is that objects disappear from the ‘world’ but remain in memory, resulting in very strange behaviour.
To add to my suggestion above, you could also use a touch joint to keep an object in place, or simply use a weld joint to attach it to a static object and move that.
While I heavily recommend against fighting the physics engine, directly moving static objects via their .x,.y values does appear to have minimal side effects. The safest way is to use a very strong touch joint though. Don’t say I didn’t warn you.
You could create a piston joint between a static object somewhere just off-screen and the player object. The joint would be oriented from left to right. Be aware that if other objects collide with it it might get pushed away from the axis, but test it out.
Maybe I’m not understanding what you want to do, but can you set isSensor=true on the player so physics collisions don’t push it at all?
Jay
oh dang that would’ve worked but I figured out a different way to fix it thanks though!
I would have added an enterframe listener with a object.y = yOrigin (where yOrigin is the Y you want).
How did you fix the problem ? Maybe this could help someone in the same case.
I wouldn’t do that if I were you. It is directly fighting the Box2D physics engine and will eventually cause catastrophic problems in your code. One situation I’ve seen is that objects disappear from the ‘world’ but remain in memory, resulting in very strange behaviour.
To add to my suggestion above, you could also use a touch joint to keep an object in place, or simply use a weld joint to attach it to a static object and move that.
While I heavily recommend against fighting the physics engine, directly moving static objects via their .x,.y values does appear to have minimal side effects. The safest way is to use a very strong touch joint though. Don’t say I didn’t warn you.