Hello! I’m new to Unity.
I have a lot of the basic movement I want in my 3d game I just I need to add air velocity and slowing down the strafing in the air
My Movement code right know:
public KeyCode RunKey = KeyCode.LeftShift;
public KeyCode JumpKey = KeyCode.Space;
public float MoveSmoothTime;
public float GravityStrength;
public float JumpStrength;
public float WalkSpeed;
public float RunSpeed;
private float CurrentSpeed;
private CharacterController Controller;
private Vector3 CurrentMoveVelocity;
private Vector3 MoveDampVelocoty;
private Vector3 CurrentForceVelocity;
void Start()
{
Controller = GetComponent<CharacterController>();
}
void Update()
{
Ray groundCheckRay = new Ray(transform.position, Vector3.down);
Vector3 PlayerInput = new Vector3
{
x = Input.GetAxisRaw("Horizontal"),
y = 0f,
z = Input.GetAxisRaw("Vertical"),
};
if (PlayerInput.magnitude > 1f)
{
PlayerInput.Normalize();
}
Vector3 MoveVector = transform.TransformDirection(PlayerInput);
CurrentSpeed = WalkSpeed;
if(Input.GetKey(RunKey) && Input.GetAxis("Vertical") > 0f)
{
CurrentSpeed = RunSpeed;
}
CurrentMoveVelocity = Vector3.SmoothDamp(
CurrentMoveVelocity,
MoveVector * CurrentSpeed,
ref MoveDampVelocoty,
MoveSmoothTime
);
Controller.Move(CurrentMoveVelocity * Time.deltaTime);
if (Physics.Raycast(groundCheckRay, 1.1f))
{
CurrentForceVelocity.y = -2f;
if (Input.GetKey(JumpKey))
{
if (Input.GetKey(KeyCode.S) && Input.GetKey(JumpKey))
{
}
else if (Input.GetAxis("Vertical") > 0f)
{
CurrentForceVelocity.y = JumpStrength;
}
}
}
else
{
CurrentForceVelocity.y -= GravityStrength * Time.deltaTime;
}
Controller.Move(CurrentForceVelocity * Time.deltaTime);
}
For any help I would be grateful I’ve been on Unity for less than a month so tell me any big mistakes and criticism they would be very helpful.