// Update is called once per frame void Update() { Debug.Log(Input.GetKeyDown(KeyCode.Space)); if (stuckTo != null && Input.GetKeyDown(KeyCode.Space)) { Vector3 tempNormal = stuckTo.normal; Debug.Log(tempNormal + " is the normal jumped from"); UnstickPlayerOver(stuckTo); gameObject.GetComponent <Rigidbody>().velocity = new Vector3(tempNormal.x * 6.0f, tempNormal.y * 4.0f + 12.0f, tempNormal.z * 6.0f); } InteractableSurface pointedAt = PointingAt(); if (pointedAt != null) { pointedAt.onHover(); if (Input.GetMouseButtonDown(0)) { pointedAt.onClickDown(); } } //fall check //for testing if (transform.position.y < -50) { transform.position = new Vector3(0, 1, 0); } }
//check to see if we're pointing to an interactable surface public InteractableSurface PointingAt() { //http://answers.unity3d.com/questions/181594/how-to-get-mouse-cursor-position-on-plane-and-set.html //https://docs.unity3d.com/ScriptReference/Camera.ScreenPointToRay.html //https://docs.unity3d.com/ScriptReference/Input-mousePosition.html Ray pointingRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit pointingTo = new RaycastHit(); if (Physics.Raycast(pointingRay, out pointingTo, interactiveLayerMask)) { //if the thing we're pointing at is an interactable surface, set its contact point to return it InteractableSurface temp = pointingTo.transform.gameObject.GetComponent <InteractableSurface>(); if (temp != null) { contactPoint = pointingTo.point; return(temp); } } return(null); }
public void UnstickPlayerOver(InteractableSurface surface) { gameObject.GetComponent <Rigidbody>().isKinematic = false; gameObject.transform.position += surface.normal * floorJumpOffset; stuckTo = null; }
public void StickPlayerTo(InteractableSurface surface) { gameObject.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0); gameObject.GetComponent <Rigidbody>().isKinematic = true; stuckTo = surface; }