playMaker

Author Topic: Rotate a Character Along a Wall Without Slowing Down?  (Read 2307 times)

Spazdaxx

  • Playmaker Newbie
  • *
  • Posts: 5
Rotate a Character Along a Wall Without Slowing Down?
« on: September 09, 2018, 09:52:56 PM »
Hey, a bit new to Playmaker!

I've spent most of my day trying to figure this out: When the player character walks into a wall, instead of the player character kind of grinding against it, I would like it to rotate parallel to the wall and continue without stopping. Attached is a gif with what I want on the Right and what is currently occurring on the Left:



On my Player I have a FSM with one state to control the character.

In that one state, I am first using 'Get Axis Vector' to store Player Movement relative to the Main Camera. Then, in that same state, I am using 'Smooth Look At Direction' to make the character face the direction it moves.

I think the solution has something to do with 'Get Collision Info' and then maybe utilizing the Contact Point and Contact Normal to rotate the character parallel to the wall but I'm not entirely sure how.

Any help is greatly appreciated! :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Rotate a Character Along a Wall Without Slowing Down?
« Reply #1 on: September 10, 2018, 02:15:57 AM »
Hi,

 it's your physics Material that you need to tweak for your walls:

https://docs.unity3d.com/Manual/class-PhysicMaterial.html

frictions should be 0.

Bye,

 Jean

Spazdaxx

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Rotate a Character Along a Wall Without Slowing Down?
« Reply #2 on: September 10, 2018, 08:49:10 PM »
So I add a frictionless physics material to the box collider on my walls?

Thanks for the idea! I gave it a shot but the player cube still slows down and doesn't rotate parallel to the wall. (Gif Attached)

I tried adding a box collider with zero friction to the player as well but that didn't change anything.

Does the Player need a Rigidbody or something?

Maybe I set up the Physics Material wrong? I have it set to:
Dynamic Friction: 0
Static Friction: 0
Bounciness: 0
Friction Combine: Multiply
Bounce Combine: Average

Thanks for being patient with me. I'm determined to get this working!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Rotate a Character Along a Wall Without Slowing Down?
« Reply #3 on: September 10, 2018, 10:17:49 PM »
Hi.
I think the fritcion is not the main issue , but the movement direction is.

I think with some raycasts you can determine the correct rotation.

Have a ray cast a little bit a little bit outside the left corner casting forward, same for the right side (if both sides are needed)
the ray should only have a short distance.
if the raycast hits a wall rotate the cube when no more wall rotate back.

but it depends also on how you move the cube.

Transform and set to local would work on this.

There might be other solutions tho, this is the one that came up in my head :)
« Last Edit: September 10, 2018, 10:20:00 PM by djaydino »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Rotate a Character Along a Wall Without Slowing Down?
« Reply #4 on: September 11, 2018, 04:09:46 AM »
Hi,

Well, the question would be how did you get the cube behaviour on the right side of your gif in the first place?

Bye,

 Jean

Spazdaxx

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Rotate a Character Along a Wall Without Slowing Down?
« Reply #5 on: September 12, 2018, 01:24:50 AM »
It looks like the dual raycasts may have it!

I have attached a Unity Package with my progress so far.

I used Unity 2017.3.1f1 and Playmaker 1.9.0 along with some custom Actions procured from the Ecosystem Browser. If you go to Edit a FSM on the Player prefab, it should tell you what actions you are missing. So if Actions are missing, just type them into the Ecosystem Browser and add them to your project!

There are no Physics Materials on any object in this scene. So it is possible to do without dealing with them. However, I've been reading around and there are a few other forum posts that say it can be done with Physics Materials. Has anyone had any luck with this method?

For the current raycast method I am using, it was mainly figuring out how to take the resulting vector3 input and toggle from the Player_Movement+Raycast_L_Normal, Player_Movement, and Player_Movement+Raycast_R_Normal depending on what, if any, raycast was currently being triggered every frame. (Lots of bools converted to floats and used as lerp values to lerp between two Vector3's) This is probably not even close to the best, most uber-optimal way to achieve this result, though it's a start.

Right now, it talks to a simple PlayerMovement FSM using a few global variables but since it's all calculated in the same state, it could probably just be added to the PlayerMovement FSM instead of being separate.

The tricky part was making this all occur in real-time in the same single state since the alternative causes jitteriness thanks to the values being reset each time it jumps between the states. (My bad though, I was re-calculating the Raycast Variables completely on each state. Not the best idea...)

Currently, the Player will rotate back to its Player Movement orientation when the user stops giving input which doesn't leave the Player standing parallel to the wall's Normal. It's very slightly noticeable, but not a deal breaker by any means. Ideally, the Player would just stay facing the way they are. Though, this may not be possible if one of the Raycasts is being triggered.

As an idea, maybe it would be better to do this by manipulating the Vector3's via Quaternions? https://forum.unity.com/threads/how-do-i-slide-player-along-a-wall-smoothly.278978/

Thanks for the help, you guys! :)