How do I lean/tilt my character in the direction of movement.
So I'm making a simple 2D puzzle platformer, where the player is a simple rectangle and has to navigate through levels collecting coins. So far I've made a demo level and a working player movement script which allows for horizontal movement, jumping, couching and implementation for an animator, however the movement looks a bit boring compared to the rest of the scene so I need a sript that will lean/tilt the player 15 or so degrees when the user presses down on either of the movement keys then returns to its original position when they let go to give it a smoother appearance without the need to implement it in via my animator as this would cause issues with my Box Collider and shadow caster.
This is my player movement script:
public CharacterController2D controller;
public Animator animator;
public float runSpeed = 0f;
float horizontalMove = 0f;
bool jump = false;
bool crouch = false;
void Update () {
horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
if (Input.GetButtonDown("Jump"))
{
jump = true;
animator.SetBool("IsJumping", true);
}
if (Input.GetButtonDown("Crouch"))
{
crouch = true;
} else if (Input.GetButtonUp("Crouch"))
{
crouch = false;
}
}
public void OnLanding ()
{
animator.SetBool("IsJumping", false);
}
void FixedUpdate () {
controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
jump = false;
}
}
To understand what I'm talking about watch this video at 9m:07s : https://www.youtube.com/watch?v=nvbQ9_bzx1k
I either want to incorporate the leaning/tilting into this one or maybe a seperate one. Any help would be greatly appreciated, thanks.
Your answer
Follow this Question
Related Questions
GO with rigid body, hierarchy best practices 0 Answers
My Player Is moving all over the place! 0 Answers
c# script for player movement and jumping using touch pad for android 0 Answers
Simultaneously moving using two inputs W D or Up LEFT to move diagonally 0 Answers
playableGraph stop working 1 Answer