Skip to main content
Code formatting, correcting tags
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

im trying to rotate Rotate the player in a certain way that makes it look like he is sliding

I'm trying to make my first game in unityUnity: a 3d platformer inspired by the classic crash bandicootCrash Bandicoot games,.

I've managed to make most of the movement howeverwith the character control script below. However, I don't know how I can do a slide/crouch since what.

What I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state,.

this is basically the motion I want to do but, but in all the axis

I thought about making the player rotate on a specific axis but when he turns the axis don'tdoesn't change so now I'm kind of lost in what to do.

this is basically the motion I want to do but, but in all the axis

using UnityEngine;

public class PlayerMovement : MonoBehaviour {


public class PlayerMovement : MonoBehaviour
{

    public CharacterController controller;

    public float speed = 10f;

    //turnning smoothness

    public float turnSmoothTime = 0.1f;
    float turnSmoothVelocity;

    //jump controls

    public float jumpHeight = 3f;
    public float gravity = -29.43f;
    Vector3 velocity;
    bool isGrounded;

    //gravity check
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < 0)
        {
            velocity.y = -1f;
        }

       //player movement on both axis

        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
       
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);

        if (Input.GetKeyDown("space") && isGrounded)
        {
            velocity.y += Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
        
        if (direction.magnitude >= 0.1f)
        {
            //player turning depending on where moving

            float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); 
            transform.rotation = Quaternion.Euler(0f, angle, 0f);
            
            controller.Move(direction * speed * Time.deltaTime);
            
        }
            
    }
}

}

im trying to rotate the player in a certain way that makes it look like he is sliding

I'm trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I've managed to make most of the movement however I don't know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don't change so now I'm kind of lost in what to do.

this is basically the motion I want to do but, but in all the axis

using UnityEngine;

public class PlayerMovement : MonoBehaviour {

public CharacterController controller;

public float speed = 10f;

//turnning smoothness

public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;

//jump controls

public float jumpHeight = 3f;
public float gravity = -29.43f;
Vector3 velocity;
bool isGrounded;

//gravity check
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;

// Update is called once per frame
void Update()
{
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

    if(isGrounded && velocity.y < 0)
    {
        velocity.y = -1f;
    }

   //player movement on both axis

    float horizontal = Input.GetAxisRaw("Horizontal");
    float vertical = Input.GetAxisRaw("Vertical");
    
    Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
   
    velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);

    if (Input.GetKeyDown("space") && isGrounded)
    {
        velocity.y += Mathf.Sqrt(jumpHeight * -2f * gravity);
    }
    
    if (direction.magnitude >= 0.1f)
    {
        //player turning depending on where moving

        float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
        float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); 
        transform.rotation = Quaternion.Euler(0f, angle, 0f);
        
        controller.Move(direction * speed * Time.deltaTime);
        
    }
        
}

}

Rotate the player in a certain way that makes it look like he is sliding

I'm trying to make my first game in Unity: a 3d platformer inspired by the classic Crash Bandicoot games.

I've managed to make most of the movement with the character control script below. However, I don't know how I can do a slide/crouch.

What I want to do is to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state.

this is basically the motion I want to do but, but in all the axis

I thought about making the player rotate on a specific axis but when he turns the axis doesn't change so now I'm kind of lost in what to do.

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    public CharacterController controller;

    public float speed = 10f;

    //turnning smoothness

    public float turnSmoothTime = 0.1f;
    float turnSmoothVelocity;

    //jump controls

    public float jumpHeight = 3f;
    public float gravity = -29.43f;
    Vector3 velocity;
    bool isGrounded;

    //gravity check
    public Transform groundCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    // Update is called once per frame
    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if(isGrounded && velocity.y < 0)
        {
            velocity.y = -1f;
        }

       //player movement on both axis

        float horizontal = Input.GetAxisRaw("Horizontal");
        float vertical = Input.GetAxisRaw("Vertical");
        
        Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
       
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);

        if (Input.GetKeyDown("space") && isGrounded)
        {
            velocity.y += Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
        
        if (direction.magnitude >= 0.1f)
        {
            //player turning depending on where moving

            float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
            float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); 
            transform.rotation = Quaternion.Euler(0f, angle, 0f);
            
            controller.Move(direction * speed * Time.deltaTime);
            
        }
            
    }
}
added 1831 characters in body
Source Link

I'm trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I've managed to make most of the movement however I don't know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don't change so now I'm kind of lost in what to do.

this is basically the motion I want to do but, but in all the axis

using UnityEngine;

public class PlayerMovement : MonoBehaviour {

public CharacterController controller;

public float speed = 10f;

//turnning smoothness

public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;

//jump controls

public float jumpHeight = 3f;
public float gravity = -29.43f;
Vector3 velocity;
bool isGrounded;

//gravity check
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;

// Update is called once per frame
void Update()
{
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

    if(isGrounded && velocity.y < 0)
    {
        velocity.y = -1f;
    }

   //player movement on both axis

    float horizontal = Input.GetAxisRaw("Horizontal");
    float vertical = Input.GetAxisRaw("Vertical");
    
    Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
   
    velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);

    if (Input.GetKeyDown("space") && isGrounded)
    {
        velocity.y += Mathf.Sqrt(jumpHeight * -2f * gravity);
    }
    
    if (direction.magnitude >= 0.1f)
    {
        //player turning depending on where moving

        float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
        float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); 
        transform.rotation = Quaternion.Euler(0f, angle, 0f);
        
        controller.Move(direction * speed * Time.deltaTime);
        
    }
        
}

}

I'm trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I've managed to make most of the movement however I don't know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don't change so now I'm kind of lost in what to do.

this is basically the motion I want to do but, but in all the axis

I'm trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I've managed to make most of the movement however I don't know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don't change so now I'm kind of lost in what to do.

this is basically the motion I want to do but, but in all the axis

using UnityEngine;

public class PlayerMovement : MonoBehaviour {

public CharacterController controller;

public float speed = 10f;

//turnning smoothness

public float turnSmoothTime = 0.1f;
float turnSmoothVelocity;

//jump controls

public float jumpHeight = 3f;
public float gravity = -29.43f;
Vector3 velocity;
bool isGrounded;

//gravity check
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;

// Update is called once per frame
void Update()
{
    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

    if(isGrounded && velocity.y < 0)
    {
        velocity.y = -1f;
    }

   //player movement on both axis

    float horizontal = Input.GetAxisRaw("Horizontal");
    float vertical = Input.GetAxisRaw("Vertical");
    
    Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
   
    velocity.y += gravity * Time.deltaTime;
    controller.Move(velocity * Time.deltaTime);

    if (Input.GetKeyDown("space") && isGrounded)
    {
        velocity.y += Mathf.Sqrt(jumpHeight * -2f * gravity);
    }
    
    if (direction.magnitude >= 0.1f)
    {
        //player turning depending on where moving

        float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg;
        float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime); 
        transform.rotation = Quaternion.Euler(0f, angle, 0f);
        
        controller.Move(direction * speed * Time.deltaTime);
        
    }
        
}

}

added 91 characters in body
Source Link

I'm trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I've managed to make most of the movement however I don't know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don't change so now I'm kind of lost in what to do.

this is basically the motion I want to do but, but in all the axis

I'm trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I've managed to make most of the movement however I don't know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don't change so now I'm kind of lost in what to do.

I'm trying to make my first game in unity a 3d platformer inspired by the classic crash bandicoot games, I've managed to make most of the movement however I don't know how I can do a slide/crouch since what I want to do is basically a way to rotate and move the player down closer to the ground and give him some more speed that decreases over time until he reaches a normal waking state, I thought about making the player rotate on a specific axis but when he turns the axis don't change so now I'm kind of lost in what to do.

this is basically the motion I want to do but, but in all the axis

Source Link
Loading