void CheckIfMoveFinished() { if (Vector3.Distance(startingPosition, transform.position) >= desiredDistance || Time.time > timeToEnd || Time.time > timeOfStart + timeOut) { movementDesired = false; ControllScript.GetInstance().notifyRobotReady(); } }
// Start is called before the first frame update void Start() { sensor = GetComponentInChildren <SensorSuite>(); rigid = GetComponent <Rigidbody>(); Rotate(-30); gameObject.layer = Physics.IgnoreRaycastLayer; ControllScript.GetInstance().RegisterRobot(this); ControllScript.GetInstance().notifyRobotReady(); }
void OnDestroy() { try { Destroy(gameObject, .2f); ControllScript.GetInstance().DeRegisterGhost(this); } catch (System.Exception e) { } }
// Update is called once per frame void Update() { if (rotationDesired) { rigid.AddTorque(0, currentTorque, 0); float virtualRotation = transform.rotation.eulerAngles.y; float virtualDesiredRotation = desiredRotation; if (Mathf.Abs(lastFrameRotation - virtualRotation) > 50) { needsToCrossThreshold = false; } lastFrameRotation = virtualRotation; if (!needsToCrossThreshold && currentTorque > 0 && virtualRotation > virtualDesiredRotation) { rotationDesired = false; ControllScript.GetInstance().notifyRobotReady(); } if (!needsToCrossThreshold && currentTorque < 0 && virtualRotation < virtualDesiredRotation) { rotationDesired = false; ControllScript.GetInstance().notifyRobotReady(); } } if (!movementDesired) { return; } rigid.AddForce(transform.forward * desiredPower); if (rigid.velocity.magnitude > MaxVelocity) { rigid.velocity.Normalize(); rigid.velocity *= MaxVelocity; } CheckIfMoveFinished(); }
void Start() { ControllScript.GetInstance().RegisterGhost(this); }