public void Pickup() { // Get nearest m_CurrentInteracteble = GetNearestInteractable(); // Null check if (!m_CurrentInteracteble) { return; } // Already held, check if (m_CurrentInteracteble.m_ActiveHand) { m_CurrentInteracteble.m_ActiveHand.Drop(); } // Position m_CurrentInteracteble.transform.position = transform.position; // Attach Rigidbody targetBody = m_CurrentInteracteble.GetComponent <Rigidbody>(); m_Joint.connectedBody = targetBody; // Set active hand m_CurrentInteracteble.m_ActiveHand = this; }
public void FollowTarge(Interacteble newTarget) { agent.stoppingDistance = newTarget.radius * .8f; agent.updateRotation = false; target = newTarget.interactionTransform; }
void RemoveFocus() { if (focus != null) { focus.OnDefocused(); } focus = null; motor.StopFollowingTarget(); }
private void OnTriggerStay(Collider other) { Interacteble interacteble = other.GetComponent <Interacteble>(); if (interacteble != null && !inRangeGo.Contains(other.gameObject)) { inRangeGo.Add(other.gameObject); } }
public InteractionButton(Node node, int nodeIndex, Interacteble target, int targetIndex, EditorController controllerReference) { parentNode = node; parentIndex = nodeIndex; interaction = target; index = targetIndex; type = ButtonEditorType.INTERACTABLE; controller = controllerReference; }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // FindObjectOfType<AudioManager>().Play("On_My_Way"); motor.MoveToPoint(hit.point); RemoveFocus(); mNavMeshAgent.destination = hit.point; } } if (mNavMeshAgent.remainingDistance <= mNavMeshAgent.stoppingDistance) { mRunning = false; FindObjectOfType <AudioManager>().Play("test"); } else { mRunning = true; } mAnimator.SetBool("running", mRunning); if (Input.GetMouseButtonDown(1)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { Interacteble interacteble = hit.collider.GetComponent <Interacteble>(); FindObjectOfType <AudioManager>().Play("gun"); if (interacteble != null) { SetFocus(interacteble); } if (mNavMeshAgent.remainingDistance <= mNavMeshAgent.stoppingDistance) { mRunning = true; } } } }
void SetFocus(Interacteble newFocus) { if (newFocus != focus) { if (focus != null) { focus.OnDefocused(); } focus = newFocus; motor.FollowTarget(newFocus); } newFocus.OnFocused(transform); }
private void SelectJob() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); LayerMask newMask = ~(_invertMask ? ~_jobLayer.value : _jobLayer.value); if (Physics.Raycast(ray, out hit, 10000, newMask)) { Interacteble interacteble = hit.collider.GetComponent <Interacteble>(); if (interacteble != null && Input.GetButtonDown("LeftMouseButtom")) { _npc.SelectJob(interacteble); ResetManager(); } } }
private Interacteble GetNearestInteractable() { Interacteble nearest = null; float minDistance = float.MaxValue; float distance = 0.0f; foreach (Interacteble interactable in m_ContactInteractebles) { distance = (interactable.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; nearest = interactable; } } return(nearest); }
public void Drop() { // Null check if (!m_CurrentInteracteble) { return; } // Aply velocity Rigidbody targetBody = m_CurrentInteracteble.GetComponent <Rigidbody>(); targetBody.velocity = m_Pose.GetVelocity(); targetBody.angularVelocity = m_Pose.GetAngularVelocity(); // Detach m_Joint.connectedBody = null; // Clear m_CurrentInteracteble.m_ActiveHand = null; m_CurrentInteracteble = null; }
public void Command(Ray ray) { RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { //Set focus Interacteble interactable = hit.collider.GetComponent <Interacteble>(); if (interactable != null) { SetFocus(interactable); } else { RemoveFocus(); //Move entity to pos if (Physics.Raycast(ray, out hit, 100, movmentMask)) { motor.MoveToPoint(hit.point); } } } }
void Update() { if (EventSystem.current.IsPointerOverGameObject()) { return; } if (Input.GetMouseButton(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, movementMask)) { // Debug.Log("We Hit " + hit.collider.name + " " + hit.point); //Move our player to what we hit motor.MoveToPoint(hit.point); //Stop focusing any objects RemoveFocus(); } } if (Input.GetMouseButton(1)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { //Debug.Log("We Hit " + hit.collider.name + " " + hit.point); //Check if we hit an interactble Interacteble interacteble = hit.collider.GetComponent <Interacteble>(); //If we did, set it as our focus if (interacteble != null) { SetFocus(interacteble); } } } }
private void Update() { ray = _cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, _getItemDistance)) { if (_lastInterateble = hit.transform.GetComponent <Interacteble>()) { _lastInterateble.Interact(this); HelpingText.enabled = true; } } else { if (_lastRetentionBlock) { _lastRetentionBlock.useGravity = true; _lastRetentionBlock = null; } _holdSlider.parent.parent.gameObject.SetActive(false); HelpingText.enabled = false; CanHolding = true; IsStartHold = true; } }
void RemoveFocus() { focus = null; }
public void SetInteraction(Interacteble newInteractable) { interaction = newInteractable; }
public void AddInteraction(Interacteble newInteraction) { possibleInteractions.Add(newInteraction); }
public void CreateInteraction(Interacteble interaction) { currentNode.AddInteraction(interaction); }
public void FollowTarget(Interacteble newTarget) { agent.stoppingDistance = newTarget.radius * 0.8f; target = newTarget.interactionTransform; }
private void Awake() { entity = true; motor = GetComponent <UnitMotor>(); focus = null; }
void FixedUpdate() { // calculating the closest interaction GameObject Closest = colsestGo(inRangeGo, InteractingArea); durationEPressed(); //interacting with objects if (Input.GetKeyDown(KeyCode.E) && Closest != null) { //calculating if "Closest" is within interaction radius Vector3 diff = Closest.transform.position - InteractingArea.position; float curDistance = diff.sqrMagnitude; Interacteble interacteble = Closest.GetComponent <Interacteble>(); //continue dialouge if dialouge is showing if (diualougeDisplayed == true) { DialogueManager.DisplayNextSentence(); } //else check to interact with object in radius else if (curDistance < interactingRadius && interacteble != null || holdingObject == true) { interacteble.Interact(); //if object is a text interaction if (interacteble.InteractionType == Interacteble.typeOfInteraction.TextInteraction) { Dialogue dialogue = interacteble.text.dialogue; if (dialogue != null) { diualougeDisplayed = true; DialogueManager.StartDialogue(dialogue); } else { Debug.LogWarning("missing Dialouge from " + interacteble.name); } } //check what type of interaction it is //if object can be picked up else if (interacteble.InteractionType == Interacteble.typeOfInteraction.pickUp) { if (!holdingObject) { currentlyHolding = Closest; holdingObject = true; //pick up object } ePressedAmount++; } else if (interacteble.InteractionType == Interacteble.typeOfInteraction.Activate) { } } } if (Input.GetKeyUp(KeyCode.E) && Closest != null) { if (timer > minimumThrowlimit) { TrowObject(); } else if (ePressedAmount > 1) { TrowObject(); } timer = 0; } //this is whats picking up the objces/dropping it if (holdingObject) { PickUp(); } }
public void SelectJob(Interacteble interacteble) { _defending = false; _interacteble = interacteble; _target = interacteble.gameObject.transform.position; }
void SetFocus(Interacteble newFocus) { focus = newFocus; }
// Update is called once per frame void Update() { keyDownCheck(); keyUpCheck(); #region Camera Movment //X if (forwards && zSpeed < moveSpeedMax) { zSpeed += moveSpeed; } if (backwards && zSpeed > -moveSpeedMax) { zSpeed -= moveSpeed; } if (!backwards && !forwards) { if (zSpeed > 0.009f) { zSpeed -= friction; } else if (zSpeed < -0.009f) { zSpeed += friction; } else { zSpeed = 0; } } //Y if (leftwards && xSpeed > -moveSpeedMax) { xSpeed -= moveSpeed; } if (rightwards && xSpeed < moveSpeedMax) { xSpeed += moveSpeed; } if (!leftwards && !rightwards) { if (xSpeed > 0.009f) { xSpeed -= friction; } else if (xSpeed < -0.009f) { xSpeed += friction; } else { xSpeed = 0; } } #endregion #region Zoom float scroll = Input.GetAxis("Mouse ScrollWheel") * zoomSpeed; float distance = Vector3.Distance(Camera.main.transform.position, this.transform.position); if (distance - scroll < minZoom) { scroll = distance - minZoom; } if (distance - scroll > maxZoom) { scroll = distance - maxZoom; } if (distance > minZoom && scroll > 0) { Camera.main.transform.position = Vector3.MoveTowards(Camera.main.transform.position, this.transform.position, scroll); } if (distance < maxZoom && scroll < 0) { Camera.main.transform.position = Vector3.MoveTowards(Camera.main.transform.position, this.transform.position, scroll); } #endregion #region Rotation //Q & E rotation if (leftRotation && rotation < maxRotationSpeed) { rotation += rotationSpeed; } if (rightRotation && rotation > -maxRotationSpeed) { rotation -= rotationSpeed; } if (!leftRotation && !rightRotation) { if (rotation > 0.009f) { rotation -= rotationFriction; } else if (rotation < -0.009f) { rotation += rotationFriction; } else { rotation = 0; } } else if (!leftMB) { Camera.main.transform.RotateAround(this.gameObject.transform.position, Vector3.up, rotation); this.gameObject.transform.Rotate(Vector3.up, rotation); } if (leftMB && mEnabled) { rotation = Input.GetAxis("Mouse X") * rotationSpeedMouse; Camera.main.transform.RotateAround(this.gameObject.transform.position, Vector3.up, rotation); this.gameObject.transform.Rotate(Vector3.up, rotation); } #endregion #region Pitch float pitch = Input.GetAxis("Mouse Y") * pitchSpeed; if (rightMB && leftMB && mEnabled) { float zAngle = Camera.main.transform.rotation.eulerAngles.x; if (zAngle > minPitch && pitch > 0) { Camera.main.transform.Rotate(-pitch, 0, 0); } if (zAngle < maxPitch && pitch < 0) { Camera.main.transform.Rotate(-pitch, 0, 0); } } #endregion if (!mEnabled) { #region Select if (Input.GetMouseButtonDown(0)) { //Creating Ray Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; //Check what it his if (Physics.Raycast(ray, out hit, 10000)) { Interacteble interactable = hit.collider.GetComponent <Interacteble>(); if (interactable != null) { SetFocus(interactable); } else { RemoveFocus(); } } } #endregion if (Input.GetMouseButtonDown(1) && focus != null) { if (focus.entity) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Unit unit = (Unit)focus; unit.Command(ray); } } } speed = new Vector3(xSpeed, ySpeed, zSpeed); speed = Quaternion.Euler(0, Camera.main.transform.rotation.eulerAngles.y / 2, 0) * speed; if (Camera.main.transform.rotation.y < 0) { speed *= -1; } this.gameObject.transform.Translate(speed); }