- Home /
Question by
JoltenDev · Feb 24, 2020 at 06:19 AM ·
transformpositionplayertransform.positionreset-position
My character's y position gets reset on play.
Every time I run my game my character's y position gets set back to 2.98 specifically(even when I change it in the inspector), I've read over my script a few times and I looked to see if anybody else was having the same problem as I was, but I couldn't find anything. Please help, thanks! Here's my code-
void LateUpdate()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
controller.slopeLimit = slopeGLimit;
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = Vector3.Normalize(transform.right * x + transform.forward * z);
Vector3 relativeMove = new Vector3(Camera.main.transform.TransformVector(move).x, 0f, Camera.main.transform.TransformVector(move).z).normalized;
if (Input.GetButtonDown("Jump") && isGrounded)
{
controller.slopeLimit = slopeJLimit;
velocity.y = Mathf.Sqrt(jumpHeight * -2 * gravity);
}
if ((controller.collisionFlags & CollisionFlags.Above) != 0)
{
velocity.y = -2f;
}
controller.Move(relativeMove * pSpeed * Time.deltaTime);
controller.Move(velocity * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
}
}
Comment