Question by
Auraxium · Oct 17, 2020 at 08:42 PM ·
scripting problemmovementscript.3rd person controller
Cant find why character doesnt move forward with this movement script
public Transform cam;
void FixedUpdate() {
direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnsmoothvelo, turnSmoothTIme); //smooth turning
transform.rotation = Quaternion.Euler(0f, angle, 0f);
}
targetVelocity = direction;
targetVelocity *= speed;
velocityChange = (targetVelocity - rigidbody.velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
}
If i hold "w" my character only moves in one direction regardless of where the camera is or the direction its facing. How can I fix this?
Comment