Repair change direction

This commit is contained in:
haitem 2022-01-29 00:40:14 +01:00
parent b598d87f52
commit 8bc6bcdcc1

View File

@ -11,15 +11,12 @@ public class PlayerController : MonoBehaviour
public float lookXLimit = 7.5f; public float lookXLimit = 7.5f;
public Camera playerCamera; public Camera playerCamera;
Vector3 moveDirection = Vector3.zero; Vector3 moveDirection = Vector3.zero;
CharacterController characterController;
public float rotationX = 0; public float rotationX = 0;
// Start is called before the first frame update // Start is called before the first frame update
[HideInInspector] [HideInInspector]
bool canMove = true; bool canMove = true;
Rigidbody rb; Rigidbody rb;
private GameObject collisionGameObject = null;
float moveDirectionY; float moveDirectionY;
public Vector3 jump; public Vector3 jump;
@ -28,7 +25,6 @@ public class PlayerController : MonoBehaviour
void Start() void Start()
{ {
rb = GetComponent<Rigidbody>(); rb = GetComponent<Rigidbody>();
characterController = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked; Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false; Cursor.visible = false;
jump = new Vector3(0.0f, 2.0f, 0.0f); jump = new Vector3(0.0f, 2.0f, 0.0f);
@ -53,35 +49,29 @@ public class PlayerController : MonoBehaviour
Debug.Log("Jump"); Debug.Log("Jump");
rb.AddForce(transform.up * jumpSpeed * 500 * Time.deltaTime, ForceMode.Impulse); rb.AddForce(transform.up * jumpSpeed * 500 * Time.deltaTime, ForceMode.Impulse);
} }
if(this.collisionGameObject != null){
transform.rotation = Quaternion.Slerp(transform.rotation, this.collisionGameObject.transform.rotation, Time.deltaTime * 1.0f);
}
rb.MovePosition(rb.position + moveDirection); rb.MovePosition(rb.position + moveDirection);
//characterController.Move(moveDirection * Time.deltaTime);
} }
void OnCollisionExit(Collision other) {
if (other.gameObject.tag == "platform")
{
this.collisionGameObject = null;
}
}
void OnCollisionEnter(Collision other) void OnCollisionEnter(Collision other)
{ {
if (other.gameObject.tag == "platform") if (other.gameObject.tag == "platform")
{ {
// FIXME:
var thisTransform = this.gameObject.transform; var thisTransform = this.gameObject.transform;
// thisTransform.eulerAngles = new Vector3(thisTransform.eulerAngles.x, thisTransform.eulerAngles.y, collision.transform.eulerAngles.z);
// thisTransform.rotation = new Quaternion(thisTransform.rotation.x, thisTransform.rotation.y, thisTransform.rotation.z, 1.0f) * Vector3.forward; Vector3 axis;
this.collisionGameObject = other.gameObject; float angle;
axis = Vector3.Cross(-transform.up, -other.transform.up);
if (axis != Vector3.zero)
{
angle = Mathf.Atan2(Vector3.Magnitude(axis), Vector3.Dot(-transform.up, -other.transform.up));
transform.RotateAround(axis, angle);
}
Vector3 gDirection = new Quaternion(0.0f, 0.0f, other.gameObject.transform.rotation.z, 1.0f) * Vector3.down; Vector3 gDirection = new Quaternion(0.0f, 0.0f, other.gameObject.transform.rotation.z, 1.0f) * Vector3.down;
Physics.gravity = gDirection * 9.81f; Physics.gravity = gDirection * 9.81f;
Debug.Log(Physics.gravity);
//Physics.gravity = -Physics.gravity;
} }
} }
} }