playMaker

Author Topic: Press "E" for Use on an gameObject  (Read 1218 times)

Tyler

  • Playmaker Newbie
  • *
  • Posts: 7
Press "E" for Use on an gameObject
« on: August 10, 2018, 03:04:31 PM »
I wanted the Key "E" to be pressed for action/use mecanism.

For example, I have a cube I want if the player is at the cube and pressing E then a function is called (save game or open door and so on).

How to achieve that?

I spend 3 hours without a result...

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Press "E" for Use on an gameObject
« Reply #1 on: August 10, 2018, 05:24:19 PM »
You can either get distance from the cube every frame and when it's under defined threshold, pressing E will start the next event - saving game for example. Or you can put a cube with only transform and trigger collider and start the event on trigger stay.
Available for Playmaker work

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Press "E" for Use on an gameObject
« Reply #2 on: August 11, 2018, 11:26:20 PM »
Hi.
For doors :
Place an object that has a collider @the door position .
Set the collider component as trigger.
And you can edit the trigger to resize it.

Place an fsm on the object and in the 1st state use a 'trigger event' and set 'on trigger stay'
Set an event to the next state.

In the next state place another 'trigger event' and set 'on trigger exit'
Set an event to the 1st state.

Also place a 'Get Key Down' and set a event to a 3rd state.

There you can then use actions to close/open the door.

Then loop back to the 2nd event.

For thing like save you can simply use the 'Get Key Down' action.