Question by
ahmedsaed2652003 · Aug 04, 2020 at 10:22 AM ·
raycastaxistransform.rotationxyz
transform.rotation is not affecting x,y,z axis
hi,
I am using this script from this tutorial to move and rotate my character using character controller
void Update()
{
groundedPlayer = characterController.isGrounded;
if (groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 movedir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
characterController.Move(movedir.normalized * speed * Time.deltaTime);
animator.SetBool("Walk", true);
if (Input.GetKeyDown(KeyCode.Space) && groundedPlayer)
{
animator.SetBool("Jump", true);
if (animator.GetBool("Jump") == true)
{
playerVelocity.y += Mathf.Sqrt(jumpHeight * -3.0f * gravityValue);
}
}
else if (Input.GetKeyUp(KeyCode.Space))
{
animator.SetBool("Jump", false);
}
}
else
{
animator.SetBool("Walk", false);
}
playerVelocity.y += gravityValue * Time.deltaTime;
characterController.Move(playerVelocity * Time.deltaTime);
if (Input.GetKey(KeyCode.LeftShift))
{
animator.SetBool("Run", true);
speed = 6f;
}
else
{
animator.SetBool("Run", false);
speed = 2f;
}
}
the problem is x,y,z axis is not rotating with the character which makes the raycast not working perfectly (the raycast is set to forward)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613004813im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Bullet Spread axis compression 0 Answers
Rotate around own vertical axis to face mouse 0 Answers
transform.rotation spazes out 0 Answers
How can I add Z axis on input manager? 0 Answers
Detecting Rays from controller input and cast from Object 0 Answers