Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Help! My object is sliding on the ground!
Started by Coder101 Feb 01 2017 05:59 AM

- - - - -
18 replies to this topic

Best Answer Coder101 , 08 February 2017 - 07:01 AM

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)

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

Hi, I have a problem. How can I make so that my physics object won't slide on the ground??

When I move with it, it sometimes starts to slide? Help! :)



[TOPIC: post.html]
#2

graham07

[GLOBAL: userInfoPane.html]
graham07
  • Contributor

  • 256 posts
  • Corona SDK

This article demonstrates how to change the physics bodies, it might get you what you're looking for.

Obviously a balloon weighs less than a crate, this sample demonstrates how to do that.

 

https://docs.coronalabs.com/guide/physics/physicsBodies/index.html



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

Add friction!



[TOPIC: post.html]
#4

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

Ok thanks! How much should I add?

[TOPIC: post.html]
#5

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

Add friction!

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



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

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



[TOPIC: post.html]
#7

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

Also, what do you mean when you say:

 

 

 

When I move with it, 


[TOPIC: post.html]
#8

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

-- 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)


[TOPIC: post.html]
#9

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

Also, what do you mean when you say:

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



[TOPIC: post.html]
#10

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

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.)

 

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

 

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

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

 

4. Temporarily get rid of 'shape' parameter and see if sliding stops.

 

5. Try this just for fun:

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

6. Buttons I don't care about.  How are you moving the object?


Edited by roaminggamer, 04 February 2017 - 11:39 AM.


[TOPIC: post.html]
#11

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

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.



[TOPIC: post.html]
#12

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

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.



[TOPIC: post.html]
#13

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

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



[TOPIC: post.html]
#14

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

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.


Edited by roaminggamer, 05 February 2017 - 11:37 AM.


[TOPIC: post.html]
#15

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

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



[TOPIC: post.html]
#16

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,641 posts
  • Corona SDK

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.


Edited by roaminggamer, 07 February 2017 - 05:26 PM.


[TOPIC: post.html]
#17

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

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. :)

 

Brent



[TOPIC: post.html]
#18

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

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.
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

[TOPIC: post.html]
#19

Coder101

[GLOBAL: userInfoPane.html]
Coder101
  • Contributor

  • 118 posts
  • Corona SDK

  Best Answer

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)



[topic_controls]
[/topic_controls]