can't get Raycast collided object's parameters

To make the character’s movement I made something like this:

 local function onEnterFrame() -- "jugador" means player in spanish --"todoGroup" is the group containing all the elements                     if gamePad.isMoving then                                          if gamePad.isMovingUp then                     jugador:translate(0, -1\* (movementSpeed \* deltaTime ))                     todoGroup:translate(0, (movementSpeed \* deltaTime ))                     jugador:setSequence("deAtrasCaminando")                     end                                          if gamePad.isMovingDown then                     jugador:translate(0, (movementSpeed \* deltaTime ))                     todoGroup:translate(0, -1\* (movementSpeed \* deltaTime ))                     jugador:setSequence("deFrenteCaminando")                     end                                          if gamePad.isMovingLeft then                     jugador:translate(-1\* (movementSpeed \* deltaTime ), 0)                     todoGroup:translate( (movementSpeed \* deltaTime ), 0)                     jugador:setSequence("deIzquierdaCaminando")                     end                                          if gamePad.isMovingRight then                     jugador:translate((movementSpeed \* deltaTime ), 0)                     todoGroup:translate(-1\* (movementSpeed \* deltaTime ), 0)                     jugador:setSequence("deDerechaCaminando")                     end                            pasosPermitidos = true                         else                     jugador:play()                           end       Runtime:addEventListener("enterFrame",onEnterFrame)

But when the character collided with any static object, the camera continued moving without the character

so I solved this with RayCasting:

&nbsp;local function onEnterFrame() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local deltaTime = getDeltaTime() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local choquesDer = physics.rayCast( jugador.x, jugador.y, jugador.x + jugador.contentWidth/2 + 5, jugador.y , "closest" ) &nbsp; &nbsp; &nbsp; &nbsp; local choquesIz = physics.rayCast( jugador.x, jugador.y, jugador.x - jugador.contentWidth/2 - 5, jugador.y , "closest" ) &nbsp; &nbsp; &nbsp; &nbsp; local choquesAba = physics.rayCast( jugador.x, jugador.y, jugador.x , jugador.y + jugador.contentHeight/2 + 5 , "closest" ) &nbsp; &nbsp; &nbsp; &nbsp; local choquesArri = physics.rayCast( jugador.x, jugador.y, jugador.x, jugador.y - jugador.contentHeight/2 - 5 , "closest" ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( choquesDer ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if choquesDer[1].position.x \> jugador.x then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gamePad.isMovingRight = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; if ( choquesIz ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if choquesIz[1].position.x \< jugador.x then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gamePad.isMovingLeft = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print(choquesIz[1].object) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; if ( choquesAba ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if choquesAba[1].position.y \> jugador.y then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gamePad.isMovingDown = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; if ( choquesArri ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if choquesArri[1].position.y \< jugador.y then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gamePad.isMovingUp = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if gamePad.isMoving then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if gamePad.isMovingUp then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:translate(0, -1\* (movementSpeed \* deltaTime )) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; todoGroup:translate(0, (movementSpeed \* deltaTime )) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:setSequence("deAtrasCaminando") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if gamePad.isMovingDown then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:translate(0, (movementSpeed \* deltaTime )) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; todoGroup:translate(0, -1\* (movementSpeed \* deltaTime )) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:setSequence("deFrenteCaminando") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if gamePad.isMovingLeft then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:translate(-1\* (movementSpeed \* deltaTime ), 0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; todoGroup:translate( (movementSpeed \* deltaTime ), 0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:setSequence("deIzquierdaCaminando") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if gamePad.isMovingRight then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:translate((movementSpeed \* deltaTime ), 0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; todoGroup:translate(-1\* (movementSpeed \* deltaTime ), 0) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:setSequence("deDerechaCaminando") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pasosPermitidos = true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --jugador:setSequence("deFrenteCaminando") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pasosPermitidos = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jugador:play() &nbsp; &nbsp; &nbsp;end&nbsp; &nbsp; &nbsp; &nbsp;Runtime:addEventListener("enterFrame",onEnterFrame)

And this worked, but I got a problem, and is that if the character collides with anything that is a physic body, it would stop, so I tried something like this:

&nbsp; &nbsp; &nbsp; &nbsp; if ( choquesDer ) then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if choquesDer[1].object.name == "borderRight" then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;gamePad.isMovingRight = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end

But it returned the parameter choquesDer[1].object.name = nil

So, is there any way to get the object’s parameters with raycasting?

or is there other more efficient way to make the character stop when collides with certain objects?

Thanks for reading, have a good afternoon :slight_smile:

It’s done exactly as you’ve already described.

choquesDer[1].object returns the display object and so choquesDer[1].object.name returns its name. Your error is most likely that whatever object the ray cast hits simply doesn’t have a name. If you draw a line from where the ray is cast to where it hits, you’ll be able to see where the problem is.

Now, there are several ways of stopping a character’s movement when it collides certain objects, but without knowing anything about your project, I can’t really offer any alternative ideas to just adding physics bodies to them. Read about collision filters in the docs if you want to create custom rules for which physics objects can collide with each others.

 

 

It’s done exactly as you’ve already described.

choquesDer[1].object returns the display object and so choquesDer[1].object.name returns its name. Your error is most likely that whatever object the ray cast hits simply doesn’t have a name. If you draw a line from where the ray is cast to where it hits, you’ll be able to see where the problem is.

Now, there are several ways of stopping a character’s movement when it collides certain objects, but without knowing anything about your project, I can’t really offer any alternative ideas to just adding physics bodies to them. Read about collision filters in the docs if you want to create custom rules for which physics objects can collide with each others.