Hey,
I have a ball, once it hits an object the ball repositions with the same velocity as it hit the object. Right
now i have ball that falls from a square then hits a second square, therefore repositions it self to where it first fell from with the same velocity. The problem is that at first the ball is dynamic and that is ok, but once it touches the second square and repositions i’d like to have a linear impulse times the velocity. The ball gets the velocity as it touches the second square when it reappears, i just need to have an impulse that is the same speed of when the ball touches the second square. Can any one help adding a linear impulse times the velocity to this? Thanks a lot! I’m sorry if i made it confusing! Try it out to see what i mean. Thanks again.
The code:
[code]
local physics = require(“physics”)
physics.start()
physics.setGravity(0,5)
local portal1 = display.newRect(150, 100, 50, 50)
portal1:setReferencePoint(display.CenterReferencePoint)
local portal2 = display.newRect(150, 400, 50, 50)
portal2:setReferencePoint(display.CenterReferencePoint)
portal2.id = “portal2”
local ball = display.newCircle(175, 200, 20)
ball:setFillColor(255,0,0)
local ball2 = display.newCircle(0, 0, 20)
ball2:setFillColor(255,0,0)
ball2.isVisible = false
ball2.x = portal1.x
ball2.y = portal1.y
– PHYSICS OBJECTS –
physics.addBody(portal1, “static”, {isSensor=true})
physics.addBody(portal2, “static”, {isSensor=true})
physics.addBody(ball, “dynamic”, {radius=20})
physics.addBody(ball2, “static”, {radius=20})
local onCollision = function(event, self)
local speedX, speedY = ball:getLinearVelocity()
if event.phase == “began” then
if event.other.id == “portal2” then
ball2.bodyType = “dynamic”
ball2:getLinearVelocity(speedX, speedY)
ball2.isVisible = true
if ball.x == portal2.x then
ball.isVisible = false
end
end
elseif event.phase == “ended” then
ball:removeSelf()
end
end
ball:addEventListener(“collision”, onCollision) [import]uid: 23689 topic_id: 14227 reply_id: 314227[/import]