/** Runs actions for the current state */ void RunState() { switch (currentState) { case BallState.Player: // Update position relative to puppy transform.position = GameObject.Find("Player").transform.position + new Vector3(0, 0, -1.1f); if (Input.GetKeyDown(KeyCode.Space)) { WorldState.ball = BallState.Air; } break; case BallState.Air: // Update position and velocity transform.position += steering.velocity * Time.deltaTime; steering.velocity += gravity * Time.deltaTime; // Stop moving if (transform.position.y <= BallController.floorHeight) { WorldState.ball = BallState.Floor; } break; case BallState.Puppy: var go = GameObject.Find("Puppy"); var controller = go.GetComponent <PuppyController>(); var offset = Kinematic.Orient2Vec(controller.kinematic.orientation) * 1.5f + new Vector3(0, 1f, 0); transform.position = go.transform.position + offset; break; } }
/** Orientation difference. Canonical implementation, as it outputs the minimal angle direction * and does not have to deal with Y coordinates in vector representations that may have miscalculations if not removed properly */ public static float OrientDiff(float source, float target) { Vector3 sourceVec = Kinematic.Orient2Vec(source); Vector3 targetVec = Kinematic.Orient2Vec(target); return(Vector3.SignedAngle(sourceVec, targetVec, Vector3.up)); }
void EnableState() { enabled = true; renderer.enabled = true; transform.position = new Vector3(0, TargetController.floorHeight, 0) + Vector3.ProjectOnPlane(player.position, Vector3.up) + Kinematic.Orient2Vec(player.orientation) * 5; }