playMaker

Author Topic: Wall running Help [SOLVED]  (Read 2356 times)

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Wall running Help [SOLVED]
« on: June 01, 2019, 05:13:54 PM »
I am so frustrated atm. I cannot seem to get down wall running.
I am trying to achieve something like this>
The process I have so far goes something like this:
*Walks near wall
*Player has collider that detects when near walls
*FSM checks if player is Grounded and near a Wall
*If both conditions are met then player is rotated by 90* so feet are on the wall and gravity is turned off

The issue comes in when the conditions are met and the character attempts to rotate then they are flung in a random direction like there is something wrong with the physics.

If it has any relevancy then I should also let you all know that I have the rigid body attached to an empty body and the child of that is the player whose animations use root motion with a collider attached to the play so they dont fall through the ground.

I dont know what I am missing.

Edit: So after many different ways of detecting when I am near a wall, I decided to go with a raycast facing the front of me. The issue I am facing now is:

*Getting the character to rotate the right direction [with his feet on the wall] regardless of the angle of the wall.

TLDR: Find a way to calculate what direction I am from a wall regardless of what WORLD SPACE the wall is at and turn my character to stand on that wall.


EDIT 2: Thanks for the answers below. I am so close to getting this down after revising the way I do wall running. The issue I am having now is getting the direction I am facing to the wall. What I mean by that is, if I am on one side of a wall then I need to apply gravity to the Z axis to stick to the wall then have my X and Y free so I can move around on that wall freely. The same is said about the other sides of the wall with X being replaced with Z. Another issue with that is that some sides use X or Z but it is - so I would need to invert the controls but I would first need to be be able to tell what direction of a wall I am on or facing then I assume I would float compare based off what direction then change the translate variables based on the sign and axis.

EDIT 3: So I ended up solving the issue. The way I was going about doing wall running was, in my case wrong. All I needed to do was:
*Smooth Look At

*Get YZ axis and feed that as a vector3 into translate and have translate on Self Space so no matter what side that it will still use the same inputs in the same directions.

*I had an issue with the rigid body and my character moving ever so slightly so I have set velocity to 0 when im on the wall and translate myself forward so that I am always sticking to the wall.

« Last Edit: June 06, 2019, 09:42:57 PM by paradiseprime »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How would I approach Wall Running
« Reply #1 on: June 02, 2019, 08:02:50 AM »
No idea how to do this, but when working with physics, it’s perhaps better to make it consistent. Rather than turning off gravity, how about rotating it towards the wall?

PlaymakerNOOB

  • Full Member
  • ***
  • Posts: 219
Re: How would I approach Wall Running
« Reply #2 on: June 02, 2019, 06:22:28 PM »
Rotating towards the wall is key.  My guess is something like a box collider at the players feet and in front of the player and whenever something hits the collider infront, rotate the player 90 degrees.  I dont think you turn off gravity.  Instead, you give your player velocity/translate in the Y axis that is equal to gravity.  This will keep them stationary on the wall.  You will also need to apply force to the X or Z axis to help keep the player attached to the building. After that, it should be like normal, with all your movements rotated 90 degrees of course.

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Re: How would I approach Wall Running
« Reply #3 on: June 03, 2019, 03:57:45 PM »
Rotating towards the wall is key.  My guess is something like a box collider at the players feet and in front of the player and whenever something hits the collider infront, rotate the player 90 degrees.  I dont think you turn off gravity.  Instead, you give your player velocity/translate in the Y axis that is equal to gravity.  This will keep them stationary on the wall.  You will also need to apply force to the X or Z axis to help keep the player attached to the building. After that, it should be like normal, with all your movements rotated 90 degrees of course.

I ended up going with raycasts because they are easier to work with from my experience and let me get specific points. I was thinking about the idea of not turning gravity off and instead having an equal force but I dont know how to apply that equal force or where to get the current force from.

I am not fully understanding the rotate towards the wall idea. I have tried "Vector3 Rotate Towards" and "Quaternion Rotate Towards" but I dont even know what to grab. I assume when it asks for the direction it means Euler Angles.

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Re: How would I approach Wall Running
« Reply #4 on: June 03, 2019, 03:59:03 PM »
No idea how to do this, but when working with physics, it’s perhaps better to make it consistent. Rather than turning off gravity, how about rotating it towards the wall?

I dont understand the rotating towards wall idea. I see 2 functions for it but both have me dumb founded. One uses euler angles and the other quaternions.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How would I approach Wall Running
« Reply #5 on: June 04, 2019, 12:34:37 PM »
Don’t know whether there’s an action for this. Gravity in Unity is apparently a vector3 and in theory can be changed so that the wall object is where gravity is pushing towards.

Here’s some old code I found on the quick:

Code: [Select]
Vector3 gravity;
 
 void Start()
 {
     gravity = Physics.gravity;
 }
 
 void FixedUpdate()
 {
     Physics.gravity = gravity;
     
     if(somethingIsTrue)
     {
         gravity.x = 0;
         gravity.y = -25;
         gravity.z = 0;
     }
 }

If not on Ecosystem, you can request actions, or else try a different approach with “add force” towards the wall, and experiment with how much. You can also try to mess with physics material and friction.

paradiseprime

  • Full Member
  • ***
  • Posts: 105
Re: How would I approach Wall Running
« Reply #6 on: June 05, 2019, 04:04:08 AM »
Don’t know whether there’s an action for this. Gravity in Unity is apparently a vector3 and in theory can be changed so that the wall object is where gravity is pushing towards.

Here’s some old code I found on the quick:

Code: [Select]
Vector3 gravity;
 
 void Start()
 {
     gravity = Physics.gravity;
 }
 
 void FixedUpdate()
 {
     Physics.gravity = gravity;
     
     if(somethingIsTrue)
     {
         gravity.x = 0;
         gravity.y = -25;
         gravity.z = 0;
     }
 }

If not on Ecosystem, you can request actions, or else try a different approach with “add force” towards the wall, and experiment with how much. You can also try to mess with physics material and friction.

Ok. This is works nicely. I changed a lot around and decided to go another route. Instead of flipping my character completely horizontally. I would instead keep him vertical since the animation of him running up the wall is him bending forward keeping the front of his mass near the wall so it looks logical. It took me a bit to realize having him be actually horizontal would look wonky when pairing it with the animation.

The way I did it was:
*get Raycast Normal and flip the X and Z then have float compares when either X or Z is 1 through -1 and apply the proper rotation through world or self space.

The issue here is it isnt consistent on all 4 sides. Is there an easier way to get the direction of an object or the direction you are facing then translate based off of your direction?