public void Run(MapCoordinates mapCoordinate) { if (mapCoordinate == null) { throw new ArgumentNullException(); } foreach (var move in this.Movement) { if ((roverCoordinate.XPoint < mapCoordinate.X || roverCoordinate.YPoint < mapCoordinate.Y) && roverCoordinate.XPoint >= 0 || roverCoordinate.YPoint >= 0) { if (move == 'M') { if (roverCoordinate.Heading == 'N' || roverCoordinate.Heading == 'E' || roverCoordinate.Heading == 'W' || roverCoordinate.Heading == 'S') { var stepcount = direction.GetStepCount(roverCoordinate.Heading); if (direction.GetAxis(roverCoordinate.Heading) == 'Y') { roverCoordinate.YPoint = roverCoordinate.YPoint + stepcount; } else if (direction.GetAxis(roverCoordinate.Heading) == 'X') { roverCoordinate.XPoint = roverCoordinate.XPoint + stepcount; } } } } roverCoordinate.Heading = direction.GetDirection(roverCoordinate.Heading.ToString() + move.ToString()); } }
// Update is called once per frame void FixedUpdate () { // TODO: Delete dirty hack before gravity is implemented if (Input.GetKeyDown (KeyCode.P)) { MoveToGround (); } Vector3 direction = director != null ? director.GetDirection () : Vector3.zero; if(Vector3.Distance (direction, Vector3.zero) > 0.01f) { float speed = Mathf.Lerp (walkVelocity.magnitude, walkSpeed, Time.deltaTime * damping); walkVelocity = direction.normalized * speed; } else { // TODO: Deccelerative lerp walkVelocity = Vector3.zero; } // TODO: Gravity // TODO: Don't hardcode rayDistance, layerMask and invertLayerMask float rayDistance = 1.1f; int layerMask = 1 << 8; layerMask = ~layerMask; Debug.DrawLine (root.position, root.position - (root.up * rayDistance)); RaycastHit hit; if(Physics.Raycast (root.position, -root.up, out hit, rayDistance, layerMask)) { gravVelocity = Vector3.zero; } else { gravVelocity += (-root.up * gravity); } velocity = walkVelocity + gravVelocity; if (mover != null) { Quaternion rot = transform.rotation; mover.Move (velocity); transform.rotation = rot; } if (rotator != null) { rotator.TryRotate (velocity.normalized); } }