Transition pass through obstacles

3 replies [Last post]
tom19921004
User offline. Last seen 5 years 24 weeks ago. Offline
Joined: 8 Mar 2013

is there a way to "go around" the obstacles when using transition?

I am using the following code to move my player object

local movePlayer = function(event)
local distancep = math.sqrt((player.x - event.x) * (player.x - event.x) + (player.y - event.y) * (player.y - event.y))
transition.to(player,{time=distancep * 10, alpha=0, x=event.x, y=event.y,transition = easing.linear} )
end

However, i notice that it will just pass through the obstacle object even though i set the obstacle to "static"

How can i fix this?

Thanks

Replies

Rob Miracle
User offline. Last seen 4 hours 44 min ago. Offline
Staff
Joined: 26 Nov 2012

You have to detect the collision between your player and your object and abort the transition if there is a collision. Transitions are not part of the physics engine and will move from point a to point b unless you stop it.

tom19921004
User offline. Last seen 5 years 24 weeks ago. Offline
Joined: 8 Mar 2013

So i wrote the following

player.preCollision = function(self, event)
player.x =player.x + math.random(0,2)
player.y = player.y + math.random(0,2)

hoping to readjust the position before the collision, but it shows that
"ERROR: Cannot translate an object before collision is resolved"

So is there anyway to go around the obstacle?

Brent Sorrentino
User offline. Last seen 1 year 3 weeks ago. Offline
Staff
Joined: 28 Nov 2012

Hello,
Certain things cannot be done in the same "app cycle" as a collision. In this scenario, you can use normal collision detection (not pre-collision), then on collision, perform your translate after a very short, imperceptible timer of 10-20 milliseconds. This should solve the error message you're getting.

Brent

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.