void BuiltInPuppetInputUpdate(BuiltInInputMode inputMode) { switch (inputMode) { case BuiltInInputMode.DefaultCameraRelative: Camera cam = Camera.main; Vector3 displacement = Vector3.zero; displacement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); float mag = Mathf.Min(1, displacement.magnitude); if (mag >= 0.01f) { //rotate stick input to camera orientation Vector3 flatcamforward = cam.transform.forward; flatcamforward.y = 0; flatcamforward.Normalize(); Quaternion camToCharacterSpace = Quaternion.FromToRotation(Vector3.forward, flatcamforward); displacement = (camToCharacterSpace * displacement); displacement.y = 0; displacement.Normalize(); displacement = displacement * mag; } else { displacement = Vector3.zero; } movementInput = displacement; if (Input.GetButtonDown("Jump") && CanJump()) { Jump(); } break; case BuiltInInputMode.ClickRaycastTarget: if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit[] hits = Physics.RaycastAll(ray); for (int i = 0; i < hits.Length; i++) { if (hits[i].collider == capsule) { continue; } if (hits[i].collider.isTrigger) { continue; } walkTarget = hits[i].point; } } break; } }
public void InitializeComponents() { animator = GetComponentInChildren <Animator>(); body = GetComponentInChildren <Rigidbody>(); if (body == null) { body = gameObject.AddComponent <Rigidbody>(); } body.constraints = RigidbodyConstraints.FreezeRotation; body.useGravity = false; capsule = GetComponentInChildren <CapsuleCollider>(); if (capsule == null) { capsule = gameObject.AddComponent <CapsuleCollider>(); } capsule.height = 2; capsule.radius = 0.5f; capsule.center = Vector3.up; builtInInputMode = BuiltInInputMode.DefaultCameraRelative; print("setting puppet control to built in default camera relative"); }