Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

round object rotate but not its image
Started by manu_1010 Oct 04 2019 12:28 PM

2 replies to this topic
ball rotation physics

Best Answer XeduR @Spyric , 04 October 2019 - 01:43 PM

You need to give the ball a friction value that isn't 0. With 0 friction, it simply glides. Giving it a friction of even 0.01 will force it to rotate.

 

Also, when you are creating the imageRect, if you want to give the object specific x and y coordinates, you need to do so via other means, e.g.

ball.x, ball.y = 20, 40

That table you've added at the end of your newImageRect function doesn't do anything and it is just ignored by the function.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

manu_1010

[GLOBAL: userInfoPane.html]
manu_1010
  • Observer

  • 3 posts
  • Corona SDK

Hello everyone, i'm creating a simple game but i'm having a problem, I have wrote this code as an example of what i want to do: 

physics = require ("physics")
physics.start( )

ball = display.newImageRect("Ball.png", 15, 15, {x=0,y=0})
physics.addBody(ball, 'dynamic' , {radius=7.5,bounce=0.8})

local downhill = display.newRect( 130, 130, 1500, 150 )
physics.addBody( downhill,"static" )
downhill.rotation = 2

In this code a ball goes downhill and you can see it going down but the image doesn't rotate, to get the effect of rotating i must put: 

ball:applyAngularImpulse( 0.01 )

How can i get the same effect without doing that? I'm making a game where you basically launch a ball to break some brick and can't make the ball image rotate. Thanks in advance!



[TOPIC: post.html]
#2

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 944 posts
  • Corona SDK

  Best Answer

You need to give the ball a friction value that isn't 0. With 0 friction, it simply glides. Giving it a friction of even 0.01 will force it to rotate.

 

Also, when you are creating the imageRect, if you want to give the object specific x and y coordinates, you need to do so via other means, e.g.

ball.x, ball.y = 20, 40

That table you've added at the end of your newImageRect function doesn't do anything and it is just ignored by the function.


  • manu_1010 likes this

[TOPIC: post.html]
#3

manu_1010

[GLOBAL: userInfoPane.html]
manu_1010
  • Observer

  • 3 posts
  • Corona SDK

Thanks, i've tried this solution but i was always writing after the physics.addBody this

ball.friction = 0.01

instead of something like:

physics.addBody(ball, 'dynamic' , {radius=7.5,bounce=0.8,friction=0.01})

now, for some reason i realized i was doing it wrong, it works correctly, thanks again!




[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: ball, rotation, physics