public override SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters) { SteeringOutput steering = base.CalculateSteering(deltaTime, parameters); steering.linearVelocity *= -1; return(steering); }
public override void Draw(SteeringParameters parameters) { foreach (WeightedBehaviour weightedBehaviour in weightedBehaviours) { weightedBehaviour.behaviour.Draw(parameters); } }
public override void Draw(SteeringParameters parameters) { foreach (SteeringBehaviour behaviour in priorityBehaviours) { behaviour.Draw(parameters); } }
public override void Draw(SteeringParameters parameters) { Gizmos.color = Color.cyan; Gizmos.DrawSphere(parameters.position, 0.2f); Gizmos.DrawSphere(targetPosition, 0.2f); Gizmos.color = Color.white; Gizmos.DrawLine(parameters.position, targetPosition); }
public override void Draw(SteeringParameters parameters) { Vector2 circleCenter = parameters.Direction * distance + parameters.position; Gizmos.color = Color.white; Gizmos.DrawLine(parameters.position, circleCenter); Gizmos.color = Color.magenta; Gizmos.DrawWireSphere(circleCenter, radius); }
public override SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters) { SteeringOutput steering = new SteeringOutput(); steering.linearVelocity = targetPosition - parameters.position; steering.linearVelocity.Normalize(); steering.succesful = true; //velocity *= parameters.maxLinearSpeed; return(steering); }
public override SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters) { SteeringOutput steering = new SteeringOutput(); foreach (SteeringBehaviour behaviour in priorityBehaviours) { steering = behaviour.CalculateSteering(deltaTime, parameters); if (steering.succesful) { break; } } return(steering); }
public override void Draw(SteeringParameters parameters) { float angleRadians = angleOffset * Mathf.Deg2Rad; Vector2 newDirection = parameters.Direction.x * new Vector2(Mathf.Cos(angleRadians), Mathf.Sin(angleRadians)) + parameters.Direction.y * new Vector2(-Mathf.Sin(angleRadians), Mathf.Cos(angleRadians)); Vector2 ahead = parameters.position + (newDirection * maxSeeAhead); Vector2 ahead2 = parameters.position + (newDirection * maxSeeAhead * 0.5f); Gizmos.DrawWireSphere(targetPosition, radius); Gizmos.color = Color.red; Gizmos.DrawWireSphere(ahead, 0.2f); Gizmos.color = Color.green; Gizmos.DrawWireSphere(ahead2, 0.2f); }
public override SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters) { SteeringOutput steering = new SteeringOutput(); float squaredDist = (targetPosition - parameters.position).SqrMagnitude(); if (squaredDist > (evadeRadius * evadeRadius)) { return(steering); } targetPosition = targetPosition + (parameters.linearVelocity * (squaredDist / (strenght * strenght))); return(base.CalculateSteering(deltaTime, parameters)); }
public override SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters) { SteeringOutput steering = new SteeringOutput(); Vector2 circleCenter = parameters.Direction * distance; Vector2 displacement = new Vector2(Mathf.Cos(wanderAngle), Mathf.Sin(wanderAngle)) * radius; wanderAngle += UnityEngine.Random.value * angleChange - angleChange / 2.0f; //wanderAngle += UnityEngine.Random.value * angleChange - angleChange / 2.0f; steering.linearVelocity = circleCenter + displacement; steering.succesful = true; return(steering); }
protected override void OnDrawGizmosSelected() { base.OnDrawGizmosSelected(); if (!spline) { return; } SteeringParameters parameters = new SteeringParameters(); parameters.position = spline.TopNodeWorld; parameters.linearVelocity = spline.LinearVelocity; parameters.Direction = spline.GrowthDirection; behaviour.Draw(parameters); }
// Update is called once per frame protected override void Update() { base.Update(); if (Avoided) { wander.WanderAngle = spline.Orientation; } SteeringParameters parameters = new SteeringParameters(); parameters.position = spline.TopNodeWorld; parameters.linearVelocity = spline.LinearVelocity; parameters.Orientation = spline.Orientation; //Also sets direction seek.SetTarget(player.TopNodeWorld); SteeringOutput newDirection = behaviour.CalculateSteering(Time.deltaTime, parameters); spline.GrowthDirection = newDirection.linearVelocity; }
public override SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters) { SteeringOutput steering = new SteeringOutput(); float angleRadians = angleOffset * Mathf.Deg2Rad; Vector2 newDirection = parameters.Direction.x * new Vector2(Mathf.Cos(angleRadians), Mathf.Sin(angleRadians)) + parameters.Direction.y * new Vector2(-Mathf.Sin(angleRadians), Mathf.Cos(angleRadians)); Vector2 ahead = parameters.position + (newDirection * maxSeeAhead); Vector2 ahead2 = parameters.position + (newDirection * maxSeeAhead * 0.5f); Vector2 self = parameters.position; // the property "center" of the obstacle is a Vector3D. float evasionRadius = radius * radius; if ((targetPosition - ahead).SqrMagnitude() <= evasionRadius || (targetPosition - ahead2).SqrMagnitude() <= evasionRadius || (targetPosition - self).SqrMagnitude() <= evasionRadius) { steering.linearVelocity = (ahead - targetPosition).normalized; steering.succesful = true; } return(steering); }
public override SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters) { SteeringOutput steering = new SteeringOutput(); float totalWeight = 0.0f; foreach (WeightedBehaviour weightedBehaviour in weightedBehaviours) { SteeringOutput newSteering = weightedBehaviour.behaviour.CalculateSteering(deltaTime, parameters); steering.linearVelocity += weightedBehaviour.weight * newSteering.linearVelocity; steering.angularVelocity += weightedBehaviour.weight * newSteering.angularVelocity; steering.succesful |= newSteering.succesful; totalWeight += weightedBehaviour.weight; } if (totalWeight != 0.0f) { steering.linearVelocity.Normalize(); //steering.angularVelocity /= totalWeight; } return(steering); }
public virtual void Draw(SteeringParameters parameters) { }
public abstract SteeringOutput CalculateSteering(float deltaTime, SteeringParameters parameters);