- Home /
Question by
Optypack · Apr 13, 2021 at 12:11 PM ·
movementerror messagejumping object
I am always getting this error when I jump, does anyone know how to fix it??
Due to floating point precision limitations, it is recommended to bring the world coordinates to the GameObject within a smaller range.
After the error is shown in the inspector of the player in play mode, my FPS's camera goes blank. here is the code:
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
//references
Rigidbody rb;
public GroundTest GroundTest;
//input
float X, Z;
bool StartJumping;
//movement
float MovementSpeed;
public float ForwadSpeed = 1000f;
public float BackwardSpeed = 650f;
public float SidewaySpeed = 750f;
//jump
public float JumpForce = 100f;
public bool CanJump = true;
public float JumpDelay = 0.2f;
private void Awake() {
rb = GetComponent<Rigidbody>();
}
private void FixedUpdate() {
Move();
Jump();
LockCursor();
}
private void Update() {
MyInput();
Rotate();
}
void MyInput() {
Z = Input.GetAxisRaw("Vertical");
X = Input.GetAxisRaw("Horizontal");
StartJumping = Input.GetButton("Jump");
}
void Move() {
if (Z == 1) MovementSpeed = ForwadSpeed;
if (Z == -1) MovementSpeed = BackwardSpeed;
if (X == 1 || X == -1) MovementSpeed = SidewaySpeed;
Vector3 Movement = new Vector3(X, rb.velocity.y, Z);
rb.velocity = Movement * MovementSpeed * Time.deltaTime;
}
void Jump() {
if (StartJumping == true && GroundTest.IsGrounded == true && CanJump == true) {
CanJump = false;
rb.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
Invoke("ResetJump", JumpDelay);
}
}
void ResetJump() {
CanJump = true;
}
void LockCursor() {
Cursor.lockState = CursorLockMode.Locked;
if (Input.GetKey(KeyCode.Escape)) Cursor.lockState = CursorLockMode.None;
else Cursor.lockState = CursorLockMode.Locked;
}
void Rotate() {
}
}
Comment
Your answer
Follow this Question
Related Questions
how can i move a ball like in rolling sky game using mobile touch and reach the same physics ? 0 Answers
Jumping Problem 1 Answer
The file MemoryStream is corrupted! Remove it and launch unity again 6 Answers
Make object jump to fixed y position 1 Answer
Having trouble with simple 2D movement 4 Answers