void PatrollingTick() { SetAnim("walk"); // Wander and wall avoidance behavior Behavior.WanderOn(); Behavior.WallAvoidanceOn(); Behavior.SeparationOn(); Vector2 velocity = Behavior.Calculate(); Behavior.WanderOff(); Behavior.WallAvoidanceOff(); Behavior.SeparationOff(); Vector2 newPosition = Position + velocity; // makes the actor look to the new position LookAt(newPosition); MoveTo(newPosition); float distanceToTarget = CalculateDistanceToTarget(Target); if (IsTargetInFOV(Target)) { SetChaseSpeed(); // the target is in the actor´s fov, so it is time to chase him entityStateMachine.State = CHASING_PLAYER; } else if (distanceToTarget >= IDLE_DISTANCE) { // if the target is so far, do nothing entityStateMachine.State = IDLE; } }
public void Update(double time_elapsed) { //keep a record of its old position so we can update its cell later in this method m_OldPos = Pos; Vector2D SteeringForce; //calculate the combined force from each steering behavior in the vehicle's list SteeringForce = m_pSteering.Calculate(); //Acceleration = Force/Mass Vector2D acceleration = SteeringForce / m_dMass; //update velocity m_vVelocity += acceleration * time_elapsed; //make sure vehicle does not exceed maximum velocity m_vVelocity.Truncate(m_dMaxSpeed); //update the position m_vPos += m_vVelocity * time_elapsed; //update the heading if the vehicle has a non zero velocity if (m_vVelocity.LengthSq() > 0.00000001) { m_vHeading = Vector2D.Vec2DNormalize(m_vVelocity); m_vSide = m_vHeading.Perp(); } }
void Update() { Vector3 steeringForce = Vector3.ClampMagnitude(sb.Calculate(), maxForce); Vector3 acceleration = steeringForce / mass; velocity += acceleration * Time.deltaTime; velocity = Vector3.ClampMagnitude(velocity + steeringForce, maxSpeed); Debug.DrawRay(transform.position, velocity.normalized * 2, Color.green); if (velocity != Vector3.zero) { transform.position += velocity * Time.deltaTime; transform.forward = velocity.normalized; } }
public void Update(double time_elapsed) { Vector2D oldPos = Pos; Vector2D steeringForce = _behaviour.Calculate(); Vector2D acceleration = steeringForce / Mass; Velocity = acceleration * time_elapsed / 40; Velocity.Truncate((float)MaxSpeed); Pos += Velocity * time_elapsed / 40; if (Velocity.LengthSq() > float.Epsilon) { Heading = Vector2D.Normalize(Velocity); Side = Heading.Perp(); } }
private void Update() { // 以速度方向更新朝向 if (velocity.magnitude > 0.1f) { transform.up = Smooth(); } Vector2 SteeringForce = m_Steering.Calculate(); if (SteeringForce.magnitude > m_MaxForce) { SteeringForce = SteeringForce.normalized * m_MaxForce; } GetComponent <Rigidbody2D>().AddForce(SteeringForce); if (GetComponent <Rigidbody2D>().velocity.magnitude > m_MaxSpeed) { GetComponent <Rigidbody2D>().velocity = GetComponent <Rigidbody2D>().velocity.normalized *m_MaxSpeed; } }
void Update() { Vector3 steeringForce = steeringBehavior.Calculate(state, target.transform.position); if (steeringForce.magnitude < Mathf.Epsilon) { rigidbody.velocity -= rigidbody.velocity.normalized * (rigidbody.velocity.magnitude / rigidbody.mass); return; } steeringForce = new Vector3(steeringForce.x, 0f, steeringForce.z); this.steeringForce = steeringForce; Vector3 acceleration = steeringForce / 1f; this.acceleration = acceleration; rigidbody.AddForce(acceleration * Time.deltaTime, ForceMode.VelocityChange); rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxSpeed); Rotate(rigidbody.velocity); }