1 / 20

行動 (Movement)

行動 (Movement). 靜宜大學 資工系 蔡奇偉 副教授. 大綱. The Basics of Movement Algorithms Kinematic Movement Algorithms Steering Behaviors Combining Steering Behaviors Predicting Physics Jumping Coordinated Movement. 遊戲人工智慧的模型. The Movement algorithm Structure. Statics. struct Static:

shana
Download Presentation

行動 (Movement)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 行動(Movement) 靜宜大學資工系 蔡奇偉 副教授

  2. 大綱 • The Basics of Movement Algorithms • Kinematic Movement Algorithms • Steering Behaviors • Combining Steering Behaviors • Predicting Physics • Jumping • Coordinated Movement

  3. 遊戲人工智慧的模型

  4. The Movement algorithm Structure

  5. Statics • structStatic: • position # a 2D vector • orientation # a single floating point value The 2D movement axes and the 3D basis The positions of characters in the level

  6. 右手座標系統: 左手座標系統:

  7. Kinematics • struct Kinematic • position # a 2 or 3D vector • orientation # a single floating point value • velocity # another 2 or 3D vector • rotation # a single floating point value • structSteeringOutput: • linear # 加速度 a 2 or 3D vector • angular # 角加速度 a single floating point value

  8. struct Kinematic: • ... Member data as before ... • def update(steering, time): • # Update the position and orientation • position += velocity * time + • 0.5 * steering.linear * time * time • orientation += rotation * time + • 0.5 * steering.angular * time * time • # and the velocity and rotation • velocity += steering.linear * time • rotation += steering.angular * time

  9. 簡化版(因為 time 值很小) • struct Kinematic: • ... Member data as before ... • def update (steering, time): • # Update the position and orientation • position += velocity * time • orientation += rotation * time • # and the velocity and rotation • velocity += steering.linear * time • rotation += steering.angular * time

  10. Kinematic Movement Algorithms • Seek • Flee • Arriving • Wandering

  11. def getNewOrientation(currentOrientation, velocity): • # Make sure we have a velocity • if velocity.length() > 0: • # Calculate orientation using an arc tangent of • # the velocity components. • return atan2(-velocity.x, velocity.z) • # Otherwise use the current orientation • else: return currentOrientation

  12. Kinematic Seek(尋找) A kinematic seek behavior takes as input the character’s and their target’s static data. It calculates the direction from the character to the target and requests a velocity along this line. target character

  13. structKinematicSteeringOutput: • velocity • rotation • class KinematicSeek: • # Holds the static data for the character and target • character • target • # Holds the maximum speed the character can travel • maxSpeed

  14. def getSteering(): • # Create the structure for output • steering = new KinematicSteeringOutput() • # Get the direction to the target • steering.velocity = target.position- character.position • # The velocity is along this direction, at full speed • steering.velocity.normalize() • steering.velocity*= maxSpeed • # Face in the direction we want to move • character.orientation = • getNewOrientation(character.orientation,steering.velocity) • # Output the steering • steering.rotation= 0 • return steering target character

  15. Kinematic Flee(逃跑) • If we want the character to run away from their target, we can simply reverse the second line of the getSteering method to give • # Get the direction away from the target • steering.velocity= character.position - target.position • The character will then move at maximum velocity in the opposite direction. target character

  16. Arriving(抵達) (1) (2) target target target target (3) (4) character character character character 超過目標,須返回

  17. 解決方法: 一、角色進入目標範圍圈內,即表示已抵達。 二、減速接近目標。 三、在目標範圍圈才減速接近目標。 target character

  18. Wandering(徘徊) A kinematic wander behavior always moves in the direction of the character’s current orientation with maximum speed. The steering behavior modifies the character’s orientation, which allows the character to meander as it moves forward.

  19. class KinematicWander: • character • maxSpeed • # Holds the maximum rotation speed we’d like, probably • # should be smaller than the maximum possible, to allow • # a leisurely change in direction • maxRotation • def getSteering(): • # Create the structure for output • steering = new KinematicSteeringOutput() • # Get velocity from the vector form of the orientation • steering.velocity= maxSpeed* character.orientation.asVector() • # Change our orientation randomly • steering.rotation= randomBinomial() * maxRotation • # Output the steering • return steering • def randomBinomial(): • return random() - random()

  20. Steering Behaviors

More Related