playMaker

Author Topic: Auto-Jump with Raycast?  (Read 1674 times)

Prototype_6492

  • Junior Playmaker
  • **
  • Posts: 50
Auto-Jump with Raycast?
« on: August 10, 2018, 11:29:05 AM »
I need my character to jump whenever a ray is not hitting the terrain, or any ground object for the matter.

Is there a way to detect when the ray is not hitting a game object? So then it can it proceed to forcing the character to auto-jump?

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Auto-Jump with Raycast?
« Reply #1 on: August 10, 2018, 11:42:28 AM »
Put something around the camera that will move with it and serve as "nothing" and have an appropriate tag? So when you hit that instead of terrain, you will jump. Some edge colliders perhaps.
« Last Edit: August 10, 2018, 01:32:06 PM by krmko »
Available for Playmaker work

Prototype_6492

  • Junior Playmaker
  • **
  • Posts: 50
Re: Auto-Jump with Raycast?
« Reply #2 on: August 10, 2018, 01:24:25 PM »
I'm not sure why I didn't think of that. Thank you!

Doh

  • Full Member
  • ***
  • Posts: 124
Re: Auto-Jump with Raycast?
« Reply #3 on: August 12, 2018, 08:17:11 PM »
I like krmko's solution, it should be a very robust method.

If it doesn't work out though you can also set a max distance for a raycast and trigger a miss event when it doesn't hit an object.

Layers will come in handy too if you need to enable/disable the jump occurring in certain circumstances. You might consider including a state or two to setup the regrounding process that will prevent your character from endlessly jumping into the air after the initial jump. That will obviously depend on the context of your character controller though.