Dynamic Body Stop Moving

Hello everyone,

So, I have a question, I’m creating a joystick based game, and I need some dynamic bodies for collisions, (kinda walls).

My player is static (/dynamic, doesn’t change here). And when my
player collides with a wall, the wall moves with the action. How can I
stop dynamic objects moving and still have the wall stopping my player?

Thank you

Philippe

P.S.: Maybe I didn’t understood well some physics actions :stuck_out_tongue: I’m a newbie in lua

Pretty sure your played is supposed to be dynamic and the wall static?

I believe the isSensor = true is what you are looking for either way to stop your walls from moving

http://docs.coronalabs.com/api/type/Body/isSensor.html

Edit: oh wow just saw the thread date, sorry for the late reply, you’ve probably figured it out already

I have the same problem. My game is joystick type and I move the world instead of player, which is stay in the center of the screen. Could you explain how excactly isSensor can help with this problem?

I don’t know if that’s what the author of this topic wanted to know, but I will answer anton2111 at first.

I use the following method for letting my character stay in the center and the world moving around him.

The chracter is an dynamic object, the walls and all unmovable objects are static objects. The character and all objects are inside of a display group. Now you use your joystick and move the charater around. You have a function with a runtime listener, which moves the whole group in the opposite direction then the character does.

You have to do some annoying calculations here, but it’s not that hard.

Hope that helps.

Thank you, torbenratzlaff! I used exactly the same method you described. But I have a problem with interaction with walls. What do you do, when character collides with any wall? What the logic of it? Do you use sensor and then implement other world-movement? Please explain, I brake my mind already :slight_smile:

 

Hmm that’s weird. Not sure why I said isSensor would help in this case. I must have been tired or something since isSensor would make the player go through the wall I believe.

If your player is dynamic and walls are static, no isSensor involved at all, it should be false by default, then your player should be moving around the wall, depending on other physics properties. What do you want it to do exactly when it touches the wall?

Well, I just want the walls and buildings to be a solid objects - when character touch a wall he will not allowed to move further. But because I move world instead of hero, walls begin to push and character shift to the opposite side. And by the way, there some bug also - when dynamic - static interaction between them, collision event.phase become “began”, in some cases it return to “ended”, in other not. And then  it is possible to go through the wall without any collision. I will load a YouTube video to show it in 2-3 hours

Oh, finally! Problem solved!

Well, let me explain. I have to body - dynamic (hero) and static (wall). When I press a joystic I count an angle, and then dX and dY (proepries of triangle). Then I set linearVelocity to hero, and he is moving. But I need him to be in a center. So I count a distance between the center of the screen and hero Position. These new dX and dY I apply to a hero as hero:translate(dX, dY) and also to a wall - wall:translate(dX, dY). And here we go! Hero only touch a wall and cannot to go through it and so on. Here is a sample code:

-- SAMPLE COLLISION FILTERS local heroCollisionFilter = { categoryBits = 1, maskBits = 2 } local objectsCollisionFilter = { categoryBits = 2, maskBits = 1 } -- HELPS TO LOCATE OBJECTS window\_width = display.actualContentHeight window\_height = display.actualContentWidth -- PHYSICS ENGINE ON local physics = require ("physics") physics.start() physics.setGravity (0, 0) -- because it up view game -- File with general functions. In this sample only getAngle() and getVector() functions used require ("function") -- In project this group consist information about all objects in the game local world = display.newGroup() -- Initialize objects for this project local circleMove, moveArea, hero, topBorder function move (obj, dX, dY)     obj:translate(dX, dY) end function moveWorld (event)         local dX, dY = getVector (hero.direction, hero.speed) -- how far to push     hero:setLinearVelocity (dX, dY) -- move hero as a physical object     dX = window\_width / 2 - hero.x -- count distance from screen center     dY = window\_height / 2 - hero.y     move (hero, dX, dY) -- and move hero and border     move (topBorder, dX, dY)     --print (hero.x,  window\_width / 2 - hero.x) end function world:startMove ()     world.enterFrame = moveWorld     Runtime:addEventListener ("enterFrame", world) end function world:stopMove ()     hero:setLinearVelocity (0, 0) -- stop a movement     Runtime:removeEventListener ("enterFrame", world) end -- When touch joystick calculate the angle, and give this information to moveWorld() function function onMoveTouch (event)     hero.direction = getAngle (moveArea.x, moveArea.y, event.x, event.y)         circleMove.x = event.x     circleMove.y = event.y             if event.phase == "began" then         world:startMove ()     end         if event.phase == "cancelled" then         print ("CANCELL")     end         if event.phase == "ended" then                  circleMove.x = moveArea.x         circleMove.y = moveArea.y             world:stopMove ()         end end -- Visualisation of sample inteface local background = display.newImage("background.png") local moveGroup = display.newGroup () moveArea = display.newRect (moveGroup, 0,0,10,10) moveArea:setFillColor (0,0,0,0) moveArea.height = window\_height / 2 moveArea.width = moveArea.height moveArea.x = moveArea.width / 2 moveArea.y = window\_height - (moveArea.height / 2) local circleMoveBorder = display.newImageRect (moveGroup, "circle.png", moveArea.width, moveArea.height) circleMoveBorder.x = moveArea.x circleMoveBorder.y = moveArea.y circleMove = display.newImageRect (moveGroup, "circle.png", moveArea.width/4, moveArea.height/4) circleMove.x = moveArea.x circleMove.y = moveArea.y moveArea:addEventListener ("touch", onMoveTouch) hero = display.newCircle (0,0, 10) hero:setFillColor (120, 44, 220) hero.x = window\_width / 2 hero.y = window\_height / 2 hero.speed = 80 -- this variable goes to the getVector() function hero.direction = 0 topBorder = display.newRect (-100, 100, window\_width + 200, 10) topBorder:setFillColor (0,0,0) -- The main trouble right here. What to do with collisions, should I use sensor or what? hero.bodyType = "dynamic" hero.physicsOptions = {     density = 1,     radius = 10,     isSensor = false,     filter = heroCollisionFilter, } physics.addBody (hero, hero.bodyType, hero.physicsOptions) topBorder.bodyType = "static" topBorder.physicsOptions = {     density = 30,     friction = 1.0,     bounce = 0,     isSensor = false,     filter =  objectsCollisionFilter } physics.addBody (topBorder, topBorder.bodyType, topBorder.physicsOptions) local function onCollision (self, event)         -- MEET A HERO     if (event.other.physicsOptions.filter.categoryBits == 1) then             print (event.phase) -- to see is it over or not.     end end topBorder.collision = onCollision topBorder:addEventListener ("collision", topBorder)

function.lua


function getAngle (startX, startY, targetX, targetY) &nbsp;&nbsp; &nbsp;local quarter, cath\_opp, cath\_adj, hypotenuse, sin, cos, tan, newAngle &nbsp;&nbsp; &nbsp;if (targetX == startX and targetY == startY) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- zero event to predict disappearence of the arrow &nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if targetX \> startX then --\> I and II quarters &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if targetY \> startY then --\> II quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;quarter = 2&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = targetY - startY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = targetX - startX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else --\> I quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; quarter = 1 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = targetX - startX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = startY - targetY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else --\> III and IV quarters &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if targetY \> startY then --\> III quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; quarter = 3&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = startX - targetX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = targetY - startY&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else --\> IV quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; quarter = 4&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = startY - targetY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = startX - targetX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;hypotenuse = math.sqrt ((cath\_opp^2) + (cath\_adj^2)) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;--sin = cath\_opp / hypotenuse&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cos = cath\_adj / hypotenuse &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;--tan = cath\_opp / cath\_adj &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newAngle = (90 \* (quarter-1)) + math.acos (cos) \* 180 / math.pi &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;return newAngle end function getVector (angle, speed) &nbsp;&nbsp; &nbsp;local dX, dY &nbsp;&nbsp; &nbsp;if angle \>= 0 and angle \<= 90 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = speed \* (angle / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = -speed \* ((90 - angle) / 90) &nbsp;&nbsp; &nbsp;else if angle \> 90 and angle \<= 180 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = speed \* ((180 - angle) / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = speed \* ((angle - 90) / 90) &nbsp;&nbsp; &nbsp;else if angle \> 180 and angle \<= 270 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = -speed \* ((angle - 180) / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = speed \* ((270 - angle) / 90) &nbsp;&nbsp; &nbsp;else if angle \> 270 and angle \<= 360 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = -speed \* ((360 - angle) / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = -speed \* ((angle - 270) / 90) &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;return dX, dY end

Great, you got it.

That was what I originally meant by moving the group containing the character in and the walls in the opposite direction.

Should have written it clearer I think :wink:

Pretty sure your played is supposed to be dynamic and the wall static?

I believe the isSensor = true is what you are looking for either way to stop your walls from moving

http://docs.coronalabs.com/api/type/Body/isSensor.html

Edit: oh wow just saw the thread date, sorry for the late reply, you’ve probably figured it out already

I have the same problem. My game is joystick type and I move the world instead of player, which is stay in the center of the screen. Could you explain how excactly isSensor can help with this problem?

I don’t know if that’s what the author of this topic wanted to know, but I will answer anton2111 at first.

I use the following method for letting my character stay in the center and the world moving around him.

The chracter is an dynamic object, the walls and all unmovable objects are static objects. The character and all objects are inside of a display group. Now you use your joystick and move the charater around. You have a function with a runtime listener, which moves the whole group in the opposite direction then the character does.

You have to do some annoying calculations here, but it’s not that hard.

Hope that helps.

Thank you, torbenratzlaff! I used exactly the same method you described. But I have a problem with interaction with walls. What do you do, when character collides with any wall? What the logic of it? Do you use sensor and then implement other world-movement? Please explain, I brake my mind already :slight_smile:

 

Well done guys

Hmm that’s weird. Not sure why I said isSensor would help in this case. I must have been tired or something since isSensor would make the player go through the wall I believe.

If your player is dynamic and walls are static, no isSensor involved at all, it should be false by default, then your player should be moving around the wall, depending on other physics properties. What do you want it to do exactly when it touches the wall?

Well, I just want the walls and buildings to be a solid objects - when character touch a wall he will not allowed to move further. But because I move world instead of hero, walls begin to push and character shift to the opposite side. And by the way, there some bug also - when dynamic - static interaction between them, collision event.phase become “began”, in some cases it return to “ended”, in other not. And then  it is possible to go through the wall without any collision. I will load a YouTube video to show it in 2-3 hours

Oh, finally! Problem solved!

Well, let me explain. I have to body - dynamic (hero) and static (wall). When I press a joystic I count an angle, and then dX and dY (proepries of triangle). Then I set linearVelocity to hero, and he is moving. But I need him to be in a center. So I count a distance between the center of the screen and hero Position. These new dX and dY I apply to a hero as hero:translate(dX, dY) and also to a wall - wall:translate(dX, dY). And here we go! Hero only touch a wall and cannot to go through it and so on. Here is a sample code:

-- SAMPLE COLLISION FILTERS local heroCollisionFilter = { categoryBits = 1, maskBits = 2 } local objectsCollisionFilter = { categoryBits = 2, maskBits = 1 } -- HELPS TO LOCATE OBJECTS window\_width = display.actualContentHeight window\_height = display.actualContentWidth -- PHYSICS ENGINE ON local physics = require ("physics") physics.start() physics.setGravity (0, 0) -- because it up view game -- File with general functions. In this sample only getAngle() and getVector() functions used require ("function") -- In project this group consist information about all objects in the game local world = display.newGroup() -- Initialize objects for this project local circleMove, moveArea, hero, topBorder function move (obj, dX, dY) &nbsp;&nbsp; &nbsp;obj:translate(dX, dY) end function moveWorld (event)&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;local dX, dY = getVector (hero.direction, hero.speed) -- how far to push &nbsp;&nbsp; &nbsp;hero:setLinearVelocity (dX, dY) -- move hero as a physical object &nbsp;&nbsp; &nbsp;dX = window\_width / 2 - hero.x -- count distance from screen center &nbsp;&nbsp; &nbsp;dY = window\_height / 2 - hero.y &nbsp;&nbsp; &nbsp;move (hero, dX, dY) -- and move hero and border &nbsp;&nbsp; &nbsp;move (topBorder, dX, dY) &nbsp;&nbsp; &nbsp;--print (hero.x,&nbsp; window\_width / 2 - hero.x) end function world:startMove () &nbsp;&nbsp; &nbsp;world.enterFrame = moveWorld &nbsp;&nbsp; &nbsp;Runtime:addEventListener ("enterFrame", world) end function world:stopMove () &nbsp;&nbsp; &nbsp;hero:setLinearVelocity (0, 0) -- stop a movement &nbsp;&nbsp; &nbsp;Runtime:removeEventListener ("enterFrame", world) end -- When touch joystick calculate the angle, and give this information to moveWorld() function function onMoveTouch (event) &nbsp;&nbsp; &nbsp;hero.direction = getAngle (moveArea.x, moveArea.y, event.x, event.y)&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;circleMove.x = event.x &nbsp;&nbsp; &nbsp;circleMove.y = event.y&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;if event.phase == "began" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;world:startMove () &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;if event.phase == "cancelled" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print ("CANCELL") &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;if event.phase == "ended" then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;circleMove.x = moveArea.x &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;circleMove.y = moveArea.y&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;world:stopMove ()&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;end end -- Visualisation of sample inteface local background = display.newImage("background.png") local moveGroup = display.newGroup () moveArea = display.newRect (moveGroup, 0,0,10,10) moveArea:setFillColor (0,0,0,0) moveArea.height = window\_height / 2 moveArea.width = moveArea.height moveArea.x = moveArea.width / 2 moveArea.y = window\_height - (moveArea.height / 2) local circleMoveBorder = display.newImageRect (moveGroup, "circle.png", moveArea.width, moveArea.height) circleMoveBorder.x = moveArea.x circleMoveBorder.y = moveArea.y circleMove = display.newImageRect (moveGroup, "circle.png", moveArea.width/4, moveArea.height/4) circleMove.x = moveArea.x circleMove.y = moveArea.y moveArea:addEventListener ("touch", onMoveTouch) hero = display.newCircle (0,0, 10) hero:setFillColor (120, 44, 220) hero.x = window\_width / 2 hero.y = window\_height / 2 hero.speed = 80 -- this variable goes to the getVector() function hero.direction = 0 topBorder = display.newRect (-100, 100, window\_width + 200, 10) topBorder:setFillColor (0,0,0) -- The main trouble right here. What to do with collisions, should I use sensor or what? hero.bodyType = "dynamic" hero.physicsOptions = { &nbsp;&nbsp; &nbsp;density = 1, &nbsp;&nbsp; &nbsp;radius = 10, &nbsp;&nbsp; &nbsp;isSensor = false, &nbsp;&nbsp; &nbsp;filter = heroCollisionFilter, } physics.addBody (hero, hero.bodyType, hero.physicsOptions) topBorder.bodyType = "static" topBorder.physicsOptions = { &nbsp;&nbsp; &nbsp;density = 30, &nbsp;&nbsp; &nbsp;friction = 1.0, &nbsp;&nbsp; &nbsp;bounce = 0, &nbsp;&nbsp; &nbsp;isSensor = false, &nbsp;&nbsp; &nbsp;filter =&nbsp; objectsCollisionFilter } physics.addBody (topBorder, topBorder.bodyType, topBorder.physicsOptions) local function onCollision (self, event)&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;-- MEET A HERO &nbsp;&nbsp; &nbsp;if (event.other.physicsOptions.filter.categoryBits == 1) then&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print (event.phase) -- to see is it over or not. &nbsp;&nbsp; &nbsp;end end topBorder.collision = onCollision topBorder:addEventListener ("collision", topBorder)

function.lua


function getAngle (startX, startY, targetX, targetY) &nbsp;&nbsp; &nbsp;local quarter, cath\_opp, cath\_adj, hypotenuse, sin, cos, tan, newAngle &nbsp;&nbsp; &nbsp;if (targetX == startX and targetY == startY) then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;-- zero event to predict disappearence of the arrow &nbsp;&nbsp; &nbsp;else &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if targetX \> startX then --\> I and II quarters &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if targetY \> startY then --\> II quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;quarter = 2&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = targetY - startY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = targetX - startX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else --\> I quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; quarter = 1 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = targetX - startX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = startY - targetY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else --\> III and IV quarters &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if targetY \> startY then --\> III quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; quarter = 3&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = startX - targetX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = targetY - startY&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else --\> IV quarter &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; quarter = 4&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_opp = startY - targetY &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; cath\_adj = startX - targetX &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;hypotenuse = math.sqrt ((cath\_opp^2) + (cath\_adj^2)) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;--sin = cath\_opp / hypotenuse&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cos = cath\_adj / hypotenuse &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;--tan = cath\_opp / cath\_adj &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;newAngle = (90 \* (quarter-1)) + math.acos (cos) \* 180 / math.pi &nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;return newAngle end function getVector (angle, speed) &nbsp;&nbsp; &nbsp;local dX, dY &nbsp;&nbsp; &nbsp;if angle \>= 0 and angle \<= 90 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = speed \* (angle / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = -speed \* ((90 - angle) / 90) &nbsp;&nbsp; &nbsp;else if angle \> 90 and angle \<= 180 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = speed \* ((180 - angle) / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = speed \* ((angle - 90) / 90) &nbsp;&nbsp; &nbsp;else if angle \> 180 and angle \<= 270 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = -speed \* ((angle - 180) / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = speed \* ((270 - angle) / 90) &nbsp;&nbsp; &nbsp;else if angle \> 270 and angle \<= 360 then &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dX = -speed \* ((360 - angle) / 90) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;dY = -speed \* ((angle - 270) / 90) &nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp;end&nbsp;&nbsp; &nbsp;end &nbsp;&nbsp; &nbsp;return dX, dY end

Great, you got it.

That was what I originally meant by moving the group containing the character in and the walls in the opposite direction.

Should have written it clearer I think :wink: