Question by
Herekus · Nov 12, 2017 at 09:39 AM ·
physicsaiartificial intelligencewander
Is my wander method correct?
Wander method:
public Vector2 Wander () {
targetLocation = velocity;
targetLocation += new Vector2(Random.Range(-1f, 1f) * wanderJitter, Random.Range(-1f, 1f) * wanderJitter); //print(targetLocation);
targetLocation = targetLocation.normalized * (wanderRadius + wanderDist);
targetLocation = targetLocation + new Vector2(transform.position.x, transform.position.y); print(target);
return (new Vector3(targetLocation.x, targetLocation.y, 0) - transform.position);
}
Comment
Here is Update method:
void Update () {
Vector2 steeringForce = Wander();
acceleration = steeringForce/mass;
velocity += acceleration * Time.deltaTime;
velocity = Truncate(velocity, maxSpeed);
transform.right = new Vector3(velocity.x, velocity.y, 0);
transform.position += new Vector3(velocity.x * Time.deltaTime, velocity.y * Time.deltaTime, 0);
}
Your answer
Follow this Question
Related Questions
Best way to implement a trap that activates as player runs past it? 1 Answer
Enemy raycast detects player only at constant distance 0 Answers
A little doubt about creating a Talking BOT that simulates AI, for iOS system using Unity. 0 Answers
What algorithms might be needed to build AI for a game like American Football in Unity? 1 Answer