transition.to physics problem

Hello, I am trying something new to see if I change my monster AI around. I use to use the MTE moveSpriteTo for all my logic of monsters following the player. Decided to try out transition.to to move the monsters.

The problem is I use in my gameLoop:

transition.moveTo( game.sMob_1, { x=player.levelPosX, y=player.levelPosY, time=800 } ) and the monster will go right through the players physics body. If I don’t use this transistion line I can normally run into the monster fine its only when it uses the transistion it ignores all physics. I’ve tried to setup a transistion.cancel in the onCollision functions but it seemed to still give very buggy results.

I use to do:

mte.moveSpriteTo({sprite = game.sMob_1, levelPosX = player.levelPosX, levelPosY = player.levelPosY, time = 900, transition = linear}) and the physics bodies worked fine, the monster would just continously rub against the player physics body not go through it.

Is there any other way to use some very basic method of monsters following the player? Maybe using force/velocity or something? If i can plug in the players location and set it at a speed, I couldn’t figure out any method to use force/velocity, etc.

Thanks for your time!

Hi @Azmar,

I can’t vouch for what MTE is doing, but transitions should work basically OK with physics… the thing to remember is that the transition will always attempt to complete even if it collides with something, so you need to cancel the transition if it collides with something that would stop it. It seems that you’ve tried this and encountered some buggy behavior, but I can’t know what the cause is without knowing how you’ve coded it or what MTE is doing.

It should be fairly simple to compare the location of two objects, get the angle between them, and then apply a linearVelocity (or directional force) toward the other object. There are simple functions available to get these values, if you don’t have one (I can probably locate one for you if necessary). I recommend searching the physics sub-forum for this.

Another way to make objects follow other objects is to connect them with a distance joint or touch joint. But this can be tricky unless you’re familiar with physics, Box2D, and how to set up joints. Well rather, it’s not difficult, but you should be somewhat familiar with the physics engine before attempting this.

Take care,

Brent

MTE is fine, I’m not really using any MTE for this part, I use to use the MTE code and when the moveSpriteTo code was called it would move to the location but stop directly against any physics object like normal. What I was trying to say is the code:

transition.moveTo( game.sMob_1, { x=player.levelPosX, y=player.levelPosY, time=800 } )

goes right through the player (ignoring all physics) even though they both have physics bodies and I know there is zero problems with them because when I don’t use the transition code they collide with each other. I just want the transition to hit the physics body it is suppose to collide with.

I wouldn’t mind checking out the guide for the linearVelocity idea.

Thanks for your time.

Hi Azmar,

This should be happening. Are you saying that you don’t even get a response in the console if you use…

[lua]

print(“COLLIDE!”)

[/lua]

…or similar in the collision event handler?

As I mentioned, the object will attempt to finish its transition, so it might not appear that it’s colliding (especially if its overall speed is high). But if you’re not even getting a console response, then there’s something very odd going on.

Brent

Oh yes I do get a response right when they touch, still goes inside the players body though. I tried to do the transition.cancel(object) in the collision but that didn’t seem to change anything.

I’ve tried:

local function onCollision(event)     if event.phase == "began" then         local agro = event.object1         local hit = event.object2                 elseif (agro.type == "player" and hit.type == "sMob\_1") or             (agro.type == "sMob\_1" and hit.type == "player")then             print("COLLIDE") -- detects it             transition.cancel(game.sMob\_1) -- doesn't stop the monster ... end

This line is constantly being called in the gameLoop function because it needs to constantly follow the player:

transition.moveTo( game.sMob_1, { x=player.levelPosX, y=player.levelPosY, time=800 } )

Hi Azmar,

Which line is constantly being called in the gameLoop function?

Try cancelling the transition in a preCollison handler instead.

hmm why are you using an elseif statement, surely it should just be a nested if statement?

local function onCollision(event)     if event.phase == "began" then         local agro = event.object1         local hit = event.object2                 if (agro.type == "player" and hit.type == "sMob\_1") or             (agro.type == "sMob\_1" and hit.type == "player")then             print("COLLIDE") -- detects it             transition.cancel(game.sMob\_1) -- doesn't stop the monster         end ... end

Hey guys thanks for the advice/help, it actually helped me spark a big idea (i guess just talking about stuff helps spark new ideas) and I finally got it to work the way I want. I have weapons that are based off physics that I like to spawn to push back monsters and with the MTE movement it wasn’t working the way I want it to. I ended up using the MTE for monster movement and use transition calls (the above code) when using the pushback code for monsters (this was very useful because they can go through physics walls without getting buggy because of the transition code and gave me the desired effect that i wanted!! while still always trying to move to monster through MTE).

Also I didn’t know about the preCollision and postCollision filters, I will definetly be using those in the future for some stuff.

Hi @Azmar,

I can’t vouch for what MTE is doing, but transitions should work basically OK with physics… the thing to remember is that the transition will always attempt to complete even if it collides with something, so you need to cancel the transition if it collides with something that would stop it. It seems that you’ve tried this and encountered some buggy behavior, but I can’t know what the cause is without knowing how you’ve coded it or what MTE is doing.

It should be fairly simple to compare the location of two objects, get the angle between them, and then apply a linearVelocity (or directional force) toward the other object. There are simple functions available to get these values, if you don’t have one (I can probably locate one for you if necessary). I recommend searching the physics sub-forum for this.

Another way to make objects follow other objects is to connect them with a distance joint or touch joint. But this can be tricky unless you’re familiar with physics, Box2D, and how to set up joints. Well rather, it’s not difficult, but you should be somewhat familiar with the physics engine before attempting this.

Take care,

Brent

MTE is fine, I’m not really using any MTE for this part, I use to use the MTE code and when the moveSpriteTo code was called it would move to the location but stop directly against any physics object like normal. What I was trying to say is the code:

transition.moveTo( game.sMob_1, { x=player.levelPosX, y=player.levelPosY, time=800 } )

goes right through the player (ignoring all physics) even though they both have physics bodies and I know there is zero problems with them because when I don’t use the transition code they collide with each other. I just want the transition to hit the physics body it is suppose to collide with.

I wouldn’t mind checking out the guide for the linearVelocity idea.

Thanks for your time.

Hi Azmar,

This should be happening. Are you saying that you don’t even get a response in the console if you use…

[lua]

print(“COLLIDE!”)

[/lua]

…or similar in the collision event handler?

As I mentioned, the object will attempt to finish its transition, so it might not appear that it’s colliding (especially if its overall speed is high). But if you’re not even getting a console response, then there’s something very odd going on.

Brent

Oh yes I do get a response right when they touch, still goes inside the players body though. I tried to do the transition.cancel(object) in the collision but that didn’t seem to change anything.

I’ve tried:

local function onCollision(event)     if event.phase == "began" then         local agro = event.object1         local hit = event.object2                 elseif (agro.type == "player" and hit.type == "sMob\_1") or             (agro.type == "sMob\_1" and hit.type == "player")then             print("COLLIDE") -- detects it             transition.cancel(game.sMob\_1) -- doesn't stop the monster ... end

This line is constantly being called in the gameLoop function because it needs to constantly follow the player:

transition.moveTo( game.sMob_1, { x=player.levelPosX, y=player.levelPosY, time=800 } )

Hi Azmar,

Which line is constantly being called in the gameLoop function?

Try cancelling the transition in a preCollison handler instead.

hmm why are you using an elseif statement, surely it should just be a nested if statement?

local function onCollision(event)     if event.phase == "began" then         local agro = event.object1         local hit = event.object2                 if (agro.type == "player" and hit.type == "sMob\_1") or             (agro.type == "sMob\_1" and hit.type == "player")then             print("COLLIDE") -- detects it             transition.cancel(game.sMob\_1) -- doesn't stop the monster         end ... end

Hey guys thanks for the advice/help, it actually helped me spark a big idea (i guess just talking about stuff helps spark new ideas) and I finally got it to work the way I want. I have weapons that are based off physics that I like to spawn to push back monsters and with the MTE movement it wasn’t working the way I want it to. I ended up using the MTE for monster movement and use transition calls (the above code) when using the pushback code for monsters (this was very useful because they can go through physics walls without getting buggy because of the transition code and gave me the desired effect that i wanted!! while still always trying to move to monster through MTE).

Also I didn’t know about the preCollision and postCollision filters, I will definetly be using those in the future for some stuff.