Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //I modified the code in the Update() in the AISimpleLerp code
- //that makes the object move to make it work correctly with rigidbodies
- void FixedUpdate()
- {
- if (canMove)
- {
- Vector3 direction;
- Vector3 nextPos = CalculateNextPosition(out direction);
- //the direction where it has to go
- Vector3 move_dir = (nextPos - tr.position);
- // Rotate unless we are really close to the target
- if (enableRotation && direction != Vector3.zero)
- {
- if (rotationIn2D)
- {
- /*float angle = Mathf.Atan2(direction.x, -direction.y) * Mathf.Rad2Deg + 180;
- Vector3 euler = tr.eulerAngles;
- euler.z = Mathf.LerpAngle(euler.z, angle, Time.deltaTime * rotationSpeed);*/
- //the angle the rigidbody (rb) has to rotate
- //float angle = Mathf.Atan2(nextPos.x, nextPos.y) * Mathf.Rad2Deg;
- // rb.MoveRotation(angle*Time.fixedDeltaTime);
- //it uses transform because I couldn't get it working with the rigidbody API
- transform.rotation = UtilityFunctions.FaceTo(nextPos, tr.position);
- }
- else
- {
- Quaternion rot = tr.rotation;
- Quaternion desiredRot = Quaternion.LookRotation(direction);
- //tr.rotation = Quaternion.Slerp(rot, desiredRot, Time.deltaTime * rotationSpeed);
- }
- }
- rb.MovePosition(tr.position + move_dir.normalized * speed * Time.fixedDeltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement