public Vector3 SteeringFlee(Vector3 target, float timeStep) { // FixRotation(); characterAcceleration = (character.transform.position - target); characterAcceleration.y = 0; characterAcceleration = Vector3.Normalize(characterAcceleration) * maxAcceleration; _characterVelocity = _characterVelocity + (characterAcceleration * timeStep); _characterVelocity = AdditionalVector3Tools.Limit(_characterVelocity, MaxSpeed); return(_characterVelocity); }
public void SteeringFlee() { characterAcceleration = (character.transform.position - _targetGameObject.transform.position); characterAcceleration.y = 0; characterAcceleration = Vector3.Normalize(characterAcceleration) * maxAcceleration; _characterVelocity = _characterVelocity + (characterAcceleration * Time.fixedDeltaTime); _characterVelocity = AdditionalVector3Tools.Limit(_characterVelocity, MaxSpeed); flattenYtoZero(); rigidbody.velocity = _characterVelocity; }
public void SteeringFlee(Transform target) { //get the direction of the target and normalize it characterAcceleration = (character.transform.position - target.transform.position).normalized; characterAcceleration *= maxAcceleration; _characterVelocity = _characterVelocity + (characterAcceleration * Time.fixedDeltaTime); _characterVelocity = AdditionalVector3Tools.Limit(_characterVelocity, MaxSpeed); //FixRotation(); flattenYtoZero(); character.rigidbody.velocity = _characterVelocity; }
public Vector3 SteeringSeek(Vector3 targetPos, float timeStep) { if (!hasArrived) { // FixRotation(); characterAcceleration = (targetPos - character.transform.position); characterAcceleration.y = 0; characterAcceleration = Vector3.Normalize(characterAcceleration) * maxAcceleration; _characterVelocity = _characterVelocity + (characterAcceleration * timeStep); //current velocity + desiredAcceleration* time _characterVelocity = AdditionalVector3Tools.Limit(_characterVelocity, MaxSpeed); } return(_characterVelocity); }