Hi,
In the moment I am making a very simple 3D platformer with a Rigidbody 3D. And I want to add Countermovement to get a much more snappy movement. How can I do that?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player3DMovement : MonoBehaviour
{
private Rigidbody rb;
public float speed;
public float maxSpeed;
public float counterMovement;
private float applySpeed;
Vector3 move;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
if(rb.velocity.magnitude > maxSpeed)
{
rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
}
else
{
rb.AddForce(move * speed);
}
}
}