- Home /
Question by
XXrans · Jul 09, 2017 at 10:42 AM ·
playerprogrammingproblema
I have got a problem with Player! The player shakes. What is the problem? How to fix?
public Vector3 curPosition;
public Vector3 nextPosition;
Rigidbody playerRigidbody;
float camRayLength = 100f;
public float speed;
public bool isMove = false;
int floorMask;
void Awake(){
floorMask = LayerMask.GetMask ("Floor");
playerRigidbody = GetComponent <Rigidbody> ();
}
void Start(){
isMove = false;
curPosition = transform.position;
nextPosition = transform.position;
}
void Update(){
if (Input.GetMouseButtonDown(0)){
isMove = true;
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit)) {
nextPosition = hit.point;
}
}
if (curPosition != nextPosition && isMove) {
transform.position = Vector3.MoveTowards (transform.position, nextPosition, Time.deltaTime * speed);
if (transform.position == nextPosition) {
isMove = false;
}
}
}
void Turning (){
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit floorHit;
if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask)){
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
playerRigidbody.MoveRotation (newRotation);
}
}
void FixedUpdate (){
Turning ();
}![alt text][1]
[1]: /storage/temp/97391-player.jpg
player.jpg
(99.2 kB)
Comment
Answer by Vollmondum · Jul 09, 2017 at 11:03 AM
Tick Freeze Rotation on all three axes. Solved: Player's axis was at the center of the model, thus each click moved the player to the clicked spot with that center. So moving player model inside empty object and aligning feet with the ground resolved the shake.
You'd better make a video to see what your "shakes" mean.
Answer by TrEVoR2004 · Jul 11, 2017 at 01:40 PM
Is there a animation already on your character? @XXrans