playMaker

Author Topic: [2D] Stop player when hitting wall  (Read 5418 times)

vicegold

  • Playmaker Newbie
  • *
  • Posts: 9
[2D] Stop player when hitting wall
« on: March 24, 2014, 08:57:18 AM »
Hello, i'm totally new to Unity/Playmaker, but i've managed something i've tried with other tools already, but never got it there. So now i've come to a point where i don't know how to go further. I want the player (controlled by device tilting) to stop, when he hits a wall. He already loses a life, but goes through the wall.

Both, the Player and the wall have a rigidbody2d and a 2d collider.






I always thought that the stop would be automatic, when both objects have a collider and rigidbody, but it seems i was wrong :D

Anybody here who can help me with this?


MrMitch

  • Full Member
  • ***
  • Posts: 131
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #1 on: March 24, 2014, 01:02:13 PM »
What are you using to move your Player?

vicegold

  • Playmaker Newbie
  • *
  • Posts: 9
Re: [2D] Stop player when hitting wall
« Reply #2 on: March 24, 2014, 01:27:06 PM »
Get Device Acceleration, and store the values of it in some variables. Then i move the player with these variables multiplied by 8 with "Set Velocity 2D".


MrMitch

  • Full Member
  • ***
  • Posts: 131
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #3 on: March 24, 2014, 01:49:16 PM »
Ok, have you got Colliders on both the Player and the walls?

vicegold

  • Playmaker Newbie
  • *
  • Posts: 9
Re: [2D] Stop player when hitting wall
« Reply #4 on: March 24, 2014, 02:01:22 PM »
Yes, the player has a Circle Collider 2D and the walls have Polygon Colliders 2D. And both have a Rigidbody 2D.

MrMitch

  • Full Member
  • ***
  • Posts: 131
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #5 on: March 24, 2014, 03:23:48 PM »
Ok i've never worked with Set Velocity in this manner but i think that Set Velocity doesn't listen for collision.

One thing you could try is to toggle Is Kinematic when your player collides with a wall.


vicegold

  • Playmaker Newbie
  • *
  • Posts: 9
Re: [2D] Stop player when hitting wall
« Reply #6 on: March 26, 2014, 10:16:35 AM »
What kind of moving would you use? I've tried controller move as well, but there absolutely no collision is detected. With set Velocity 2D i can manage to lose a life when hitting the wall at least :) But sadly not stopping the player from go through the wall.

(I'm pretty new to Unity, so maybe i oversee something pretty simple)

Edit: I've managed to do it! The player collides with the wall, and he loses a life.

What i've done: Removed the rigidbody of the wall, and gave the wall 2 polygon colliders. One without a trigger for collision, and one with a trigger for stuff like removing a life.

Is that a normal way to give a sprite two colliders or am i doing something wrong?
« Last Edit: March 26, 2014, 12:15:46 PM by vicegold »

MrMitch

  • Full Member
  • ***
  • Posts: 131
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #7 on: March 26, 2014, 12:50:20 PM »
I wouldn't really know what movement i'd use until i was to start setting up a similar game, as quite often with making games there is more than one way of doing the same thing.

I'm glad you managed to find a solution. I tried messing around with two polygon colliders on one sprite a while back but for my game it didn't work as i had to reshape the colliders and it would only let me reshape the first one added to the sprite but if it doesn't seem to be causing any problems then i don't see it to be an issue but in saying that someone else with more knowledge might be able to tell you why its bad idea :P

If it does start giving you any problems you could always just use two sprites and turn the sprite renderer off on one of them. That's the solution i went with for my game.