/// <summary> /// Apply an agent command to the character /// </summary> /// <returns>An observation after the action has been applied</returns> public Observation ProcessCommand(Command c, int gameTick, NavMeshContainer nav) { if (gameTick % 199 == 0) { _Character.SwitchCircleDirection(); } switch (c.cmd) { case AgentCommandType.DONOTHING: break; case AgentCommandType.MOVETOWARD: AgentCommand <Tuple <Vector3, bool> > move = c as AgentCommand <Tuple <Vector3, bool> >; MoveToward(move.arg.object1, move.arg.object2); break; case AgentCommandType.INTERACT: AgentCommand interact = c as AgentCommand; string interactWith = interact.targetId; GameObject.Find(interactWith).GetComponent <Sensor>().Trigger(); break; } observation.Observe(_Character, gameTick, nav, c.cmd); return(observation); }
public static Observation FromCharacter(string agentID, Character character, int gameTick, NavMeshContainer nav, AgentCommandType usedAction) { Observation obs = new Observation(agentID); obs.Observe(character, gameTick, nav, usedAction); return(obs); }
private void handleInteract() { bool intPressed = Input.GetButtonDown("Interact"); bool dropPressed = Input.GetButtonDown("Drop"); bool obsPressed = Input.GetButtonDown("Observe"); if (intPressed) { //always try to lock cursor Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } //drop first idk if (dropPressed) { inv.dropCurrent(); } //raycast to object? RaycastHit hitInfoInteract, hitInfoObserve; bool didHitInteract = Physics.Raycast(cam.transform.position, cam.transform.forward, out hitInfoInteract, INTERACTION_DIST, INTERACTABLE_MASK); bool didHitObserve = Physics.Raycast(cam.transform.position, cam.transform.forward, out hitInfoObserve, OBSERVATION_DIST, OBSERVABLE_MASK); //Debug.DrawRay(cam.transform.position, cam.transform.forward); if (didHitObserve) { Observation obs = hitInfoObserve.collider.GetComponent <Observation>(); if (obs != null) { cursor.sprite = cursorSee; if (obsPressed) { Debug.Log("observing..."); obs.Observe(); if (tut != null) { tut.checkedWorld(); } } } else { didHitObserve = false; } } if (didHitInteract) { Interaction i = hitInfoInteract.collider.GetComponent <Interaction>(); if (i != null) { cursor.sprite = cursorGrab; if (intPressed) { if (i.pickUp) { inv.addObject(hitInfoInteract.collider.transform.parent.gameObject); //interactions always children of objects. } else { i.doAction(); } } } else { didHitInteract = false; } } if (!didHitObserve && !didHitInteract) { cursor.sprite = cursorNone; } //switch objects float scroll = Input.GetAxis("Scroll"); bool nextButton = Input.GetButtonDown("Next"); bool prevButton = Input.GetButtonDown("Prev"); if (scroll > 0.01f || nextButton) { inv.selectNext(); if (tut != null) { tut.checkedNote(); } } else if (scroll < -0.01f || prevButton) { inv.selectPrev(); if (tut != null) { tut.checkedNote(); } } }