playMaker

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

vicegold

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
[2D] Stop player when hitting wall
« on: March 24, 2014, 05: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
    • View Profile
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #1 on: March 24, 2014, 10:02:13 AM »
What are you using to move your Player?

vicegold

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: [2D] Stop player when hitting wall
« Reply #2 on: March 24, 2014, 10:27:06 AM »
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
    • View Profile
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #3 on: March 24, 2014, 10:49:16 AM »
Ok, have you got Colliders on both the Player and the walls?

vicegold

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Re: [2D] Stop player when hitting wall
« Reply #4 on: March 24, 2014, 11:01:22 AM »
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
    • View Profile
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #5 on: March 24, 2014, 12: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
    • View Profile
Re: [2D] Stop player when hitting wall
« Reply #6 on: March 26, 2014, 07: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, 09:15:46 AM by vicegold »

MrMitch

  • Full Member
  • ***
  • Posts: 131
    • View Profile
    • Rage Quit Games - Coming Soon
Re: [2D] Stop player when hitting wall
« Reply #7 on: March 26, 2014, 09:50:20 AM »
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.