Keeping a physics body at a certain position on the x-axis even after it touches other bodies?

Hi guys,

I was digging through the documentation but couldn’t find an answer to this.

I have a physics body (the player) that has 0 friction, the player moves over a landscape that is also a physics body that changes in height, however I want to lock the players position on the x- axis.

The problem is even though friction is set to 0 he is still affected by the landscapes and will slow down and go off screen. Does anyone have any idea how I may lock him to a position on the x-axis and keep him from being effected velocity wise by the landscape? [import]uid: 26706 topic_id: 8930 reply_id: 308930[/import]

Do you need things to bounce off of him? If not, then you can turn him into a sensor. He’ll still receive collision events, but things will pass through him freely.

If you do need things to bounce off of him, have you tried setting his body type to “static”, that way, things will bounce off of him but he’ll remain in place.

Hope that helps!

P.S. If neither of those scenarios apply, could you be a little more specific, maybe with some code examples? [import]uid: 52430 topic_id: 8930 reply_id: 32634[/import]

Thank you so much for your answer :slight_smile: Sorry for not being more descriptive. The way my game works is imagine your player is on a bike and he is going up and down hills (I had to collide with the hills so I had to keep him dynamic since he would fall through the hills in static but wouldn’t be effected by gravity if he was kinematic).

I did figure out a solution though in my sleep of all places.

What I ended up doing was this:

 if(player.x) ~= (background.contentWidth \* 0.5) then  
 transition.from(player, {time = 500, x = background.contentWidth \* 0.5});  
 print("TEST 1");  
 print(background.contentWidth \* 0.5);  
 print(player.x);  
 end  

If he wasn’t in the middle of the screen I simply tweened him back where he belonged. I was able to keep the dynamic properties so he would move correctly over the terrain but still kept him from slowing down over time.

Thank you too for mentioning the sensor. I didn’t come across that in the documentation yet but it will be really useful later on! :slight_smile:

I’ve only been learning Corona for about a week (I’m used to Unity) so I’m sure more questions will come up. [import]uid: 26706 topic_id: 8930 reply_id: 32660[/import]