Help! My object is sliding on the ground!

Add friction!

Ok thanks! How much should I add?

I added 100000000000000 friction and it still happens. Also, how can I add friction or bounce in tiled?

Show the code that is used to make the object that is sliding 

  • AND - 

Show the code that is used to make the object it is sliding on.

You can format these posts with the <> tool

formatyourcode.jpg

Also, what do you mean when you say:

When I move with it, 

-- Show the character animation = display.newSprite(mySheet, sequenceData) animation.x = \_X animation.y = \_Y + \_H / 10 animation:play() physics.addBody(animation, {friction = 1000000000000000, bounce = 0, shape = {-animation.width / 4,-animation.height / 2.5, animation.width / 7,-animation.height / 2.5, animation.width / 7,animation.height / 2.1, -animation.width / 4,animation.height / 2.1}}) map.layer[1]:insert(animation)

I have made 2d platformer and when I start moving (by pressing the buttons) sometimes it just starts sliding.

  1. You showed the code for the object, but not the things it is sliding on.

_ Note: Please clean up future code posts,  that is super hard to read.  (For example replace tabs with 2 or 3 spaces then post. Also review your post and re-edit if it is hard to read.)_

  1. Even money says that shape is not making good contact with the other objects it is sliding on.

  2. Have you visually verified the shape of your body? 

See: https://docs.coronalabs.com/api/library/physics/setDrawMode.html

  1. Temporarily get rid of ‘shape’ parameter and see if sliding stops.

  2. Try this just for fun:

    – after adding the body do this: animation.friction = 10

  3. Buttons I don’t care about.  How are you moving the object?

I am moving the object with a function that has a “enterFrame” listener. In the function there is player.x = player.x + motionx. If player press left move it makes -> motionx = - speed. So yes. I am manually changing the vals.

That is the problem.  You can’t do that and expect friction to make a difference.

You are  completely bypassing the box2d calculations when you manually update the position of the object.

You must use forces and velocities if you want box2d responses to affect your object.

Ok, thanks. How can I change what I have done to applyForce() etc or transition.to?

No can do sorry.  I don’t know exactly what you’re trying to do.

However, there are a TON of samples that come with  Corona in the samples folder.  Look at the physics examples one-by-one and see if something is close to what you’re trying.

Also, you can look at the Corona Cannon example which uses Physics:

https://github.com/coronalabs-samples/CoronaCannon

Finally, I have even more examples here:

Oh, and don’t forget the guides here.  You need to understand touch, listeners, physics, and a few other topics to do what you want.

I’m just wanting to be able to move the character with 3 buttons (moveLeft, moveRight and jump). 

And I’m saying that statement actually doesn’t have an exact meaning.

I’m just wanting to be able to move the character with 3 buttons (moveLeft, moveRight and jump). 

What you and I think of ‘movement’ may be two different things. I’m really not trying to be obtuse here.

Describe the movement.

I get that you want to use buttons as the input source.  That has nothing to do with the challenge of answering your question.

Try this. Describe how the moving object moves:

  • before touching a button
  • at the beginning of the button touch
  • while the button is held
  • when the button is released
  • after the button is released

If you can’t do that, think of a game that has the input and movement style you’re looking for and give us the game name,

Alternately or additionally, if you’ve seen this in a game that has a video, share a link to the video with the time in the video the movement happens.

Hi @Coder101,

As roaminggamer says, you’re using two “separate” methods of controlling the object, and that’s usually not a good approach. Both physics and transitions can, of course, control an object, but these two systems like to wield control of that object by themselves (and they don’t get along together unless you, the developer, code them to play nicely together).

Ultimately, transitions are “more powerful” than physics. They update the position of the object on screen first and foremost, and they don’t care what the physics simulation is doing. Meanwhile, though, physics will fight back against the transition.

What you should do is control your object solely and specifically through physics-based methods, not transitions. There are more than enough ways to move an object around with physics to get the behavior you need. :slight_smile:

Brent

[quote=“roaminggamer,post:34,topic:343001”]

And I’m saying that statement actually doesn’t have an exact meaning.

What you and I think of ‘movement’ may be two different things. I’m really not trying to be obtuse here.

Describe the movement.

I get that you want to use buttons as the input source. That has nothing to do with the challenge of answering your question.

Try this. Describe how the moving object moves:

  • before touching a button
  • at the beginning of the button touch
  • while the button is held
  • when the button is released
  • after the button is released
    If you can’t do that, think of a game that has the input and movement style you’re looking for and give us the game name,

Alternately or additionally, if you’ve seen this in a game that has a video, share a link to the video with the time in the video the movement happens. [/quote]
Before touching button I want the obj to stay still or continue jump movement up and fall down(if already pressed jump button)

At beginning of a touch i want to start the movement. Etc: if I press move left, the object will continue to move left while the button is being held, unless I release the button.
Same thing here: After the release of the button I want object to stay still, unless it has just jumped. If it jumped it would continue its way up and down.

This video shows; what kind of movement system I’m trying to create: https://youtu.be/-ZWy7M32WwA

Thank you everybody for answering! I have fixed the problem.

Instead of moving the character like this:

local function moveGuy(event) player.x = player.x + motionx end Runtime:addEventListener("enterFrame", moveGuy)

I move it like this:

local function moveGuy(event) player:setLinearVelocity(motionx, 0) end Runtime:addEventListener("enterFrame", moveGuy)