I think that's a generally un-intuitive way to handle player movement, and raycasting every frame is performance intensive anyway.
You're better off:
- putting a character controller on your player (read the docs on this)
- use "get axis" to get a vector3 for "moveDirection" in the axis you want to move (XZ?)
- get if the controller is "grounded" as bool
- *convert bool(grounded) to float(gravity), true = -3, false = -20 (we set it to -3 if its grounded as this pulls the controller down a bit which keeps it grounded on slopes, and avoids issues with "grounded?", if it isnt grounded then we apply normal gravity)
- use "set vector3" to set your Y vector to "gravity"
- use controller move to now apply this movement every frame
You can also do a check to see if the guy is grounded, then check for jump key, and switch your Yvector to a jump amount (8?) before appling it with controller move (**only have 1 controller move per frame)
*this method of grabbing bools and converting them to floats is just how i do this stuff, to keep it within 1 state and simple. Hopefully you can see the basic logic and program it how you like though