I’m currently creating a 3rd person Character controller for my game.
Right now i’m able to walk with my character, the rotation of my character is controlled by the direction where my camera is facing.
To move, i’m using the Translate() function of my rigidbody.
I’m also able to jump and land with working animations using appropriates raycasts
One of the core mecanic of my “game” is to be able to walk on almost any walls
For the time being, my idea was to raycast from a “WallRay” (a gameobject in the middle of my character) in front of the character to detect a wall, the raycast is working.
For example :
We can imagine the spider is my character
And this is the result I want to achieve, plus the possibility to move freely on the wall with my inputs (wasd) and the camera.
I’ve checked a lot of topics but most of them are very old.
From what I understand I need to align the normal of the hit point by the raycast to my character and rotate it accordingly.
I also need to change the input to match the new surface?
And what about the gravity ?
I’m a little bit confused about all of this, since i’m trying for a few days now.
Raycasting will work here as you have started doing.
For now, you can create some sort of function that puts the spider on the wall and make it smoother later. So the transform.up will become the wall’s normal. You can place the spider at the point the raycast hit and adjust it as need be depending on where your object’s local origin is.
If you are using a non-kinematic rigidbody (with use gravity ticked) then this is something you will have to consider, as gravity will pull the spider down again. Although since you say you are using Translate, I am guessing it is kinematic?
Then just apply gravity in the negative transform.up direction instead of Vector3.down, etc…
When you say the rotation is controlled by the camera, is the camera behind the spider in-game or are those images in-game?
I will try to do what you are saying, put the character on the wall by changing the transform.up to the wall’s normal.
I am indeed using a non-kinematic rigidbody with use gravity ticked.
Can’t we just make it kinematic and use gravity unticked while being on a wall ?
When i say the rotation is controlled by the camera, it means that in game, the camera is behind my player. (the spider was just an example, it isn’t in-game images nor the real character i’m using, it is there just to illustrate what I want to achieve)
When I move forward with the camera behind my character, my character goes forward.
If I rotate my camera in front of the player and move forward, the player will rotate to go backward
My camera is always facing the back of my character like Dark Souls for example
Okay, well I am more experienced with the Character Controller than a rigidbody controller. Unless your game’s main point is physics, I would recommend you take a look at the CC because it is much easier to work with for standard game characters. It sounds like you’re just making a standard humanoid.
Switching between kinematic and non-kinematic is icky to me unless you have good reason. You move objects differently depending on whether its kinematic and or non-kinematic For example, on a non-kinematic rigidbody, its usually incorrect to update the transform position as you are doing.
Can you give me few examples of physics points that requires using rigidbodies over Character Controller ?
It’s not clear in my mind…
By the way, you think that i can achieve what i want (walking on walls) using Character Controller instead of rigidbody ?
And finally, can you explain me why it is incorrect to update the transform position as i’m doing (transform.Translate) for a non-kinematic rigidbody ?
Sorry, these questions might be silly but I have to understand what i’m doing correct/wrong to improve myself with Unity.
So if you had a character that you were adding forces to, or a game that really relied on physics features then you’d use a rigidbody. But rigidbodies don’t by default come with things like stepping, and also its harder to control a rigidbody by adding forces.
Using a character controller you add your own gravity, every frame you add a downwards velocity. To walk on walls that velocity would simply go towards the wall (after you’ve rotated the character of course).
And its typically incorrect to update a rigidbody that way because physics should be done in FixedUpdate because that is when the physics system updates. Updating them in Update would typically cause jittery or incorrect movement. You have to imagine how FixedUpdate is a fixed timestep (50fps), while Update is variable and they don’t line up. With a kinematic rigidbody you can move it in Update.