Hey again,
Well when it hits a wall you will apply the angularVelocity again, so it stopping shouldn’t be an issue.
What you’d do is have a function for collision on the ball. On collision if it hits something with a > x then ball.angularVeloctiy = -1550 and if it hits something with a < x then make it 1550.
Does that make sense?
Try running this as a rough example;
[lua]display.setStatusBar (display.HiddenStatusBar)
local physics = require(“physics”)
physics.start()
physics.setDrawMode( “hybrid” )
display.setStatusBar( display.HiddenStatusBar )
– Horizontal Rectangles
local myRectangle = display.newRect(0, 100, 300, 10)
myRectangle.strokeWidth = 3
physics.addBody(myRectangle, “static”)
local myRectangle2 = display.newRect(360, 100, 300, 10)
myRectangle2.strokeWidth = 3
physics.addBody(myRectangle2, “static”)
local myRectangle3 = display.newRect(-180, 200, 300, 10)
myRectangle3.strokeWidth = 3
physics.addBody(myRectangle3, “static”)
local myRectangle4 = display.newRect(180, 200, 300, 10)
myRectangle4.strokeWidth = 3
physics.addBody(myRectangle4, “static”)
local myRectangle5 = display.newRect(0, 300, 480, 10)
myRectangle5.strokeWidth = 3
physics.addBody(myRectangle5, “static”)
– Vertical Rectangles
local myRectangle = display.newRect(5, 145, 10, 50)
myRectangle.strokeWidth = 3
myRectangle.type = “wall”
physics.addBody(myRectangle, “static” )
local myRectangle2 = display.newRect(465, 145, 10, 50)
myRectangle2.strokeWidth = 3
myRectangle2.type = “wall”
physics.addBody(myRectangle2, “static” )
local myRectangle3 = display.newRect(5, 245, 10, 50)
myRectangle3.strokeWidth = 3
myRectangle3.type = “wall”
physics.addBody(myRectangle3, “static” )
local myRectangle4 = display.newRect(465, 245, 10, 50)
myRectangle4.strokeWidth = 3
myRectangle4.type = “wall”
physics.addBody(myRectangle4, “static” )
–Create a Circle
local myCircle = display.newCircle( 44, 15, 10 )
–Add a body to the Circle
physics.addBody(myCircle, “kinemetic”, { density = 0.8, friction = 0.2, bounce = 0.3, radius = 10 })
–Set the Circle angular velocity
myCircle.angularVelocity = 1550
– (Optional) assign a local variable to hold the angular velocity value
local d = myCircle.angularVelocity
function circleCol (event)
if event.other.type == “wall” and event.other.x > event.target.x then
event.target.angularVelocity = -1550
elseif event.other.type == “wall” and event.other.x < event.target.x then
event.target.angularVelocity = 1550
end
end
myCircle:addEventListener(“collision”, circleCol)[/lua]
Peach
[import]uid: 52491 topic_id: 22508 reply_id: 90086[/import]