Professional Documents
Culture Documents
Steering Behavior
• Steering behaviors extend the movement algorithms in the previous section
by adding acceleration. They are gaining larger acceptance in PC and console
game development. In some genres (such as driving games) they are
dominant; in other genres they are only just beginning to see serious use.
• Kita ketahui bahwa rumus perpindahan :
• 𝑠𝑡 = 𝑠0 + 𝑣Ԧ ∗ 𝑡
• position = position + velocity * time (perlu diingat time di unity engine menggunakan time.deltaTime)
• Atau tidak jarang nilai 0.5 dihilangkan krn nilai deltatime yg sangat kecil
GLBB
Secara sederhana perpindahan dapat menggunakan : 1 struct Steering:
• 𝑣𝑡 = 𝑣0 + 0.5 ∗ 𝑎Ԧ ∗ 𝑡 2 _linear # is an vector acceleration
• 𝑠𝑡 = 𝑠0 + 𝑣Ԧ ∗ 𝑡 3 _angular # is an vector acceleration for rotation
1 class steeringSeek:
2 velocity = vector.zero #velocity awal adalah 0
3 ....
4 def update(steering, maxSpeed, time):
5
6 #the velocity
7 velocity += 0.5 * getSteering().linear * time #steering.linear is an acceleration
8 # Check for speeding and clip
9 if velocity.length() > maxSpeed:
10 velocity.normalize()
11 velocity *= maxSpeed
12
13 #Update the position and orientation
14 position += velocity * time
15 _character.orientation = getNewOrientation(_character.orientation,_velocity)
16
1 struct Steering:
2 _linear # is an vector acceleration
Seek-steering 3 _angular # is an vector acceleration for rotation
1 class SteeringSeek:
2 _character # Static data char.
3 _target # Static data target
4 _maxAcceleration # Holds the maximum acceleration of the character
5 def getSteering():
6 _SteeringOut = new Steering()
7 _SteeringOut._linear = _target.position - _character.position # direction
8 _SteeringOut._linear.normalize() #normalize membuat resultan vektor = 1.
9 _SteeringOut._linear*= maxAcceleration # Give full acceleration along this direction
10 Return _SteeringOut
11
12
steering
- Current velocity
1 struct Circle:
2 _center : vetor3D
_radius : integer
if (mostThreatening != null) {
steerLinear = ahead - mostThreatening.center;
steerLinear = steerLinear.normalized*MAX_AVOID_FORCE;
} else {
steerLinear = vertor.zero; // nullify the avoidance force
}
return steerLinear;
}
Update : Seek plus collision avoidance
1 class steeringSeek:
2
3 _steering #variable vector untuk mengkalkulasi seluruh steering force
4 ....
5 def update(steering, maxSpeed, time):
6
7 #menggunakan steering hasil dari seek + collision avoidance
8 _steering = getSteering().linear + getCollisionAvoidance.linear
9
10 # and the velocity and rotation
11 velocity += _steering * time
12
13 # Check for speeding and clip
14 if velocity.length() > maxSpeed:
15 velocity.normalize()
16 velocity *= maxSpeed
17
18 # Update the position and orientation
19 position += velocity * time
20 _character.orientation = getNewOrientation(_character.orientation,_velocity)
21