I am a beginner at best, and I was wondering if there was a simple way of contraining the movement of my capsule character. I got the basic movement script off of the reference and made sure the constraints were on in the rigid body for movement in the z-axis, but when ever the character hit an object that is cuvered, it would be forced out of the my ideal plane, with positioning in the z-axis of 0.
Any ideas?
void Update() {
CharacterController controller = GetComponent<CharacterController>();
// is the controller on the ground?
if (controller.isGrounded) {
//Feed moveDirection with input.
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
//Multiply it by speed.
moveDirection *= speed;
//Jumping
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
//Applying gravity to the controller
moveDirection.y -= gravity * Time.deltaTime;
//Making the character move
controller.Move(moveDirection * Time.deltaTime);
}
I have tried using this
transform.position.z = 0;
but I keep getting an error.
- Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable