playMaker

Author Topic: HookShot  (Read 2146 times)

stvbabb

  • Junior Playmaker
  • **
  • Posts: 66
HookShot
« on: July 18, 2017, 02:12:07 PM »
Hello,

Has anyone made a game with a hookshot mechanic or a grappling hook mechanic using Playmaker?

I'm really not sure even where to start with this idea. Maybe cast a ray and then use arraymaker to find a target?

Any help or assistance would be awesome.

Thanks,
Steve

tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: HookShot
« Reply #1 on: July 18, 2017, 11:34:24 PM »
Hi. There are certainly many ways to go about this. I dont think I would use an array for this, as it makes more work.  ;)

I would maybe

Step 1:
Tag all places you can hookshot onto with a gameobject tag called "hookshot"

State 1 (wait button state)
1. wait for button down (to start the shot).

State 2 (check target state)
2. ray cast forwards and get returned game object
3. Use raycast filter tag option for "hookshot"
4. Check for null gameobject (because wasent hookshot). If null, go to state 3, play fail sound and go back to start state.
5. If not null, then that gameobject is your target area.
6. Play hookshot animation.

State 3 (fail state)
7. play fail sound.

State 4 (success state)
8. Move your character to the gameobject (this depends on what method you are using for movement). I would probably use an itween (or better use the hotween package because of much much better performance).

I think the more tricky part might be getting the hookshot animation to work with your character, so you might think how you want to do that. A line renderer could be good. You can draw a line between your characters position and the target. Update everyframe, so as your character moves, the line will stay at the characters body (instead of the place where the character started), and thereby "shortening" as the character moves to the position.

stvbabb

  • Junior Playmaker
  • **
  • Posts: 66
Re: HookShot
« Reply #2 on: July 19, 2017, 08:39:13 AM »
Wow, thanks! I wasn't expecting such an awesome response! I'll try this over the coming week and post my graph here.

What about this?

2. ray cast forwards and get returned game object

How do I 'get returned game object?'

Again, thank you so much, tcmeric!


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: HookShot
« Reply #3 on: July 19, 2017, 11:04:05 AM »
No worries.

I see I made one mistake. I thought the raycast action could filter by tags. It can only filter by layers. So you can make all your "hookshot areas" on one layer. Or you can give them a tag and use the action "Game Object Compare Tag", to see if they have your "hookshot" tag.

The raycast can "save" in a variable any game object that it hits. See my picture, I boxed it in red.


tcmeric

  • Beta Group
  • Hero Member
  • *
  • Posts: 768
Re: HookShot
« Reply #4 on: July 19, 2017, 11:06:25 AM »
This tutorial talks about line of sight for AI, but it uses the same principle. It uses a raycast to check what its hitting. Have a watch:

stvbabb

  • Junior Playmaker
  • **
  • Posts: 66
Re: HookShot
« Reply #5 on: July 20, 2017, 08:01:41 AM »
Wow, again, thank you so much, tcmeric! What a fantastic way to start a challenging project! I'll be starting this either tonight or tomorrow night.

And, thanks for the link!!!

Cheers,
Steve