Transition pass through obstacles

3 replies [Last post]
User offline. Last seen 5 years 37 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)),{time=distancep * 10, alpha=0, x=event.x, y=event.y,transition = easing.linear} )

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?



Rob Miracle
User offline. Last seen 11 hours 15 min ago. Offline
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.

User offline. Last seen 5 years 37 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 16 weeks ago. Offline
Joined: 28 Nov 2012

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.


Viewing options

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