GameSalad

How to stop my hero from moving when colliding with wall. (touch and move)

sionchensionchen Posts: 5Member

Hello, I'm pretty new to GS and game dev in general. I hope it is okay to ask help here.

Anyway, I've successfully created an actor (a bunny) that can move to a touched area. see code

However, when I touch a different actor (a wall in this case), which I set on collide. It keeps trying to move towards it. I can't seem to figure out how to make the bunny stop movement when colliding with the wall.

I've tried the following:

  • Setting moveX and moveY to 0 after colliding.
  • Move to self.position.x and .y after colliding.
  • Setting self.motion.linearVelocity.x and .y after colliding.

None of these seem to work. Any help is appreciated. Cheers!

Comments

  • sionchensionchen Posts: 5Member

    Okay, so I found a temporary solution to my own problem. Instead of trying to stop Bunny after colliding with wall, I was able to disable moving when touching a wall in the first place.

    Wall rules:
    When touched, change attributes moveX and Y to 0.

    Bunny rules:
    Same as screenshot shown in original post, but uncheck both "run to completion".

    ps. This doesn't completely fix the problem though. If there's a Wall between Bunny and touched area, the Bunny will walk against the wall trying to get to the otherside, which kinda looks silly. But it's acceptable for now.

  • mikejamesfishermikejamesfisher Posts: 22Member, BASIC

    If the wall has rule to collide with bunny... it should stop the bunny progress. The wall has to be not moveable. If there is an animation that makes bunny “walk” when hitting wall, maybe animate when self attribute is greater than zero... sometimes you wont get a response when its hard to understand the problem. You did put lots of details in post but still a bit confusing. Ive had “many” posts go unanswered. But the great thing is you learn more trying to solve problems on your own anyway. Its those really complex problems that these geniuses here really help best with. Good luck with bunny!

  • sionchensionchen Posts: 5Member

    Hi! Thanks for your response.
    From what I observe, colliding simply makes the actors not being able to phase through each other. The wall is indeed set to not moveable. If the movement uses keys to control the actor, then yes, colliding with wall would stop it. But since it's a "move to touched area" scheme, bunny will still try to move to that specified area even though it is blocked by the wall.

    Bunny does have an animation yes, but it should only trigger if he is in motion.

    Hope that clears up a bit of the confusion.

Sign In or Register to comment.