playMaker

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

Prototype_6492

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
Auto-Jump with Raycast?
« on: August 10, 2018, 08: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?

krmko

  • Beta Group
  • Hero Member
  • *
  • Posts: 790
    • View Profile
    • Fat Pug Studio
Re: Auto-Jump with Raycast?
« Reply #1 on: August 10, 2018, 08: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, 10:32:06 AM by krmko »

Prototype_6492

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

Doh

  • Junior Playmaker
  • **
  • Posts: 99
    • View Profile
Re: Auto-Jump with Raycast?
« Reply #3 on: August 12, 2018, 05: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.