Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Sly on August 04, 2014, 10:01:22 AM

Title: [SOLVED]Door system: Checking player direction in a Top view game
Post by: Sly on August 04, 2014, 10:01:22 AM
Hello,

I'm still making my top view 2d game.
I'm actually making the door system for it but I have some trouble.
I check a lot's of tutorial and I know how to make the basic for it.

But for for my kind of game I need the player to look at the door direction and be in the triggerzone.
How I can check if the player is checking in a certain direction/looking at the door? So the player can press "E" to open it.
Because I don't want him to be able to open a door from behind.

Thanks in advance
Title: Re: Door system: Checking player direction in a Top view game
Post by: Rabagast on August 04, 2014, 02:52:07 PM
Maybe you can use a Raycast on the Player, so the Raycast needs to hit the door before you are able to open it.
Title: Re: Door system: Checking player direction in a Top view game
Post by: Sly on August 04, 2014, 03:38:53 PM
Yes I was thinking about raycast, but I try to avoid it because my enemies already have use some. I don't know if it's taking too much performance.

I just wonder if there is other way to do it.
Title: Re: Door system: Checking player direction in a Top view game
Post by: Rabagast on August 04, 2014, 04:43:11 PM
I don't know if Raycast taking too much performance. Maybe Jean Fabre or some other experts can answer this. :)

Maybe you can have a collision trigger or something in the front of the player which is a child. And when this trigger collides with the door, you can open it.
Title: Re: Door system: Checking player direction in a Top view game
Post by: 600 on August 04, 2014, 05:00:03 PM
Hello


Maybe you can have a collision trigger or something in the front of the player which is a child. And when this trigger collides with the door, you can open it.

^This or Raycast

 If many objects use Raycast every frame it can take performance, but here - you can just shoot 1 ray(Set Repeat Interval to "0") when a Key is pressed. Then check if that object is a "door" or not and react.
I use it for car doors and pick up stuff.

Title: Re: Door system: Checking player direction in a Top view game
Post by: Rabagast on August 04, 2014, 05:28:51 PM
Then go for Raycast. :)
Title: Re: Door system: Checking player direction in a Top view game
Post by: Sly on August 05, 2014, 09:01:11 AM
Yo!

Thanks for your ideas guys! They are good for solve my problem.
I will try with the raycast using repeat interval set to 0 when press a key, like you suggest 600.

Thank you very much!
Title: Re: Door system: Checking player direction in a Top view game
Post by: Sly on August 06, 2014, 08:33:21 AM
Ok, I did it with the raycast once the action button is triggered.
My player "communicate" with the items is facing, if it's at a correct range.

The only problem is when my door is opened, I can't target it because there is no more collision, but I fixed it by adding a box collider triggerzone. So I can target even if the triggerzone don't do anything.
+My door is destructible :)

Thanks for the good ideas, thanks to playmaker awesome community!
Have a good one!
Title: Re: [SOLVED]Door system: Checking player direction in a Top view game
Post by: Rabagast on August 06, 2014, 08:44:36 AM
Nice that you fixed it. :)