playMaker

Author Topic: [SOLVED]Door system: Checking player direction in a Top view game  (Read 3302 times)

Sly

  • Full Member
  • ***
  • Posts: 123
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
« Last Edit: August 06, 2014, 08:33:48 AM by Sly »

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Door system: Checking player direction in a Top view game
« Reply #1 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.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Door system: Checking player direction in a Top view game
« Reply #2 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.

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Door system: Checking player direction in a Top view game
« Reply #3 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.
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

600

  • Beta Group
  • Hero Member
  • *
  • Posts: 715
    • Flashing Lights
Re: Door system: Checking player direction in a Top view game
« Reply #4 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.


Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: Door system: Checking player direction in a Top view game
« Reply #5 on: August 04, 2014, 05:28:51 PM »
Then go for Raycast. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Door system: Checking player direction in a Top view game
« Reply #6 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!

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Door system: Checking player direction in a Top view game
« Reply #7 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!

Rabagast

  • Hero Member
  • *****
  • Posts: 683
    • Homepage
Re: [SOLVED]Door system: Checking player direction in a Top view game
« Reply #8 on: August 06, 2014, 08:44:36 AM »
Nice that you fixed it. :)
Check out our homepage. http://www.walsberg.no
Or my personal game blog for news about my games. http://retro-tetro.walsberg.no