How do I make the player walk up walls using raycast? (making a mountain goat game prototype)
I have never fully understood how raycasts work never mind coding them. Maybe there is an easier solution but I would like to get the player character seamlessly walking up walls in first person. Cannot find a clear answer anywhere that's not from 2011 or so. I'm using the FPSWalkerEnhanced to move around which I will change when everything is in place.
Code found here: https://wiki.unity3d.com/index.php/FPSWalkerEnhanced
Answer by tormentoarmagedoom · Feb 27, 2020 at 03:03 PM
Hello.
You are little lsot I think...
First, if pretend to do a "wall climging function" you should create your own 1st person controller. If not, is much more harder to adapt a prefab controller...
Second, Raycasts for wall walking? Why? You should spend 2 hours of your time watching raycast tutorials, explanations, examples, etc... RayCast is, as its name says, a ray, a line, like a bullet", shot from where you want in the direction you want, and its used to detect the object that recieve the "impact" (called "hit in unity). Shooters is the typical example of using raycasts.
Third, you should be using trigger colliders to detect walls so you can "activate" the climbing functions.
Go investigate.
PS: Dont try to go fast, take your time, read, watch, understand, and more important: try try and try.
Good luck!
Answer by kylecat6330 · Feb 28, 2020 at 03:30 PM
Creating your own movement script is normally the best for this kind of thing, as implementing other stuff into a script can sometimes mess things up. However if you really want to do this with this script then the first thing you’d need to do is put in some if statements at the beginning of the the fixedUpdate. These should set up the requirements for the climbing. Do you need to be against the wall? Do you need to jump onto the wall? Make if statements for these conditions, and when met make playerControl = false and disable the gravity/fall function. You will then need to make a new mini control script that can be contained either in its own function/void or the if statements you made. This code should provide alternative controls for climbing. You can either rotate your character to make it so they are standing on the wall or just have them face the wall and climb up. Either way you will need to make sure that your forward/backwards controls now moves you up/down, and your movement towards/away from the wall is locked.
I’m terms of detecting the wall to climb you can do it several ways, but what comes to mind is either a trigger collider or raycast. What you use depends on what you’re trying to achieve. If you want to be able to climb up a wall coming from any direction then you should use a collider. If you want to only be able to climb if you are facing the wall then use a raycast.
Your answer
Follow this Question
Related Questions
Character Controller walking on walls? 1 Answer
How do i check for a character controller to overlap a gameobject on a specific layer 0 Answers
Raycast not detecting hit 4 Answers
Create a custom polygon collider based on overlapping ogjects 0 Answers
How to make character controller not collide with specific object? 1 Answer