Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: vicegold on March 24, 2014, 08:57:18 AM

Title: [2D] Stop player when hitting wall
Post by: vicegold 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.




(http://laurids.io/screenshots/SiCfQ.png)

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?

Title: Re: [2D] Stop player when hitting wall
Post by: MrMitch on March 24, 2014, 01:02:13 PM
What are you using to move your Player?
Title: Re: [2D] Stop player when hitting wall
Post by: vicegold 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".

(http://laurids.io/screenshots/4Q75j.png)
Title: Re: [2D] Stop player when hitting wall
Post by: MrMitch on March 24, 2014, 01:49:16 PM
Ok, have you got Colliders on both the Player and the walls?
Title: Re: [2D] Stop player when hitting wall
Post by: vicegold 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.
Title: Re: [2D] Stop player when hitting wall
Post by: MrMitch 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.

Title: Re: [2D] Stop player when hitting wall
Post by: vicegold 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?
Title: Re: [2D] Stop player when hitting wall
Post by: MrMitch 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.