Games Development 2 Entity Update - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

Games Development 2 Entity Update

Description:

Less frequently in the case of distant, non-visible or less important entities ... But avoid excessively large turning circles. Worst case circling around the target ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 18
Provided by: lauren80
Category:

less

Transcript and Presenter's Notes

Title: Games Development 2 Entity Update


1
Games Development 2Entity Update Rendering
Practicalities
  • CO3301
  • Week 10

2
Entity Update
  • We give every entity an update function, which is
    called periodically
  • Maybe every frame
  • Less frequently in the case of distant,
    non-visible or less important entities
  • The update function defines the entity behaviour
  • Perform movement rotation
  • Set and play animations
  • Receive and process messages
  • Maintain state and consider AI

3
Scene Update to Entity Update
  • We have shifted to entities after using models
  • Models are just graphical - contain no behaviour
  • All model behaviour controlled in a single global
    Scene Update function
  • No attempt to encapsulate behaviour
  • Becomes a bloated, hard to maintain function
  • Using entity-based Update is another shift of
    functionality in our generalised game engine
  • Although we retain SceneUpdate to do certain
    global update work, e.g. manage user/system input

4
Pros and Cons
  • Entity Update
  • Entity behaviour (code) and entity state (data)
    encapsulated together within each entity
  • Easier to maintain, especially for a team
  • Simpler to add scripted entity behaviour
  • Game behaviour distributed, unexpected effects
  • Scene Update
  • Global function easy to find and work with
  • But ultimately clumsy and bloated team
    unfriendly
  • Model state tends to become a set of globals

5
Entity Rendering
  • We also give each entity a render function
  • This is called every frame
  • Provided the entity is visible
  • Typically, the entity passes its current position
    / animation / textures etc. to its entity
    template
  • The template class can render any of its own
    entities given these specifics
  • Recall that the template stores the mesh
  • This is fairly similar to model/mesh rendering

6
Pre / Post Rendering
  • Modern engines often perform one or more passes
    of pre or post-rendering
  • E.g. entities might have a PreRender function
  • Would called for all (visible) entities prior to
    the main render calls
  • Different purposes for different entities
  • A models blends its animations to get the final
    matrices for rendering
  • Cameras calculate their view/projection matrix
  • Lights perform a shadow rendering pass (dynamic
    shadow mapping)
  • Some entities might do nothing

7
Games Development 2 Entity Update Example
Targeting Turning and Movement
  • CO3301
  • Week 10

8
Contents
  • Forward Movement to a Target
  • Turning
  • Dot product method
  • Turning Speed
  • Acceleration / Deceleration
  • Practicalities

9
Forward Movement to a Target
  • Have an object that needs to reach a target point
  • However, the object cant move freely
  • Has a forward velocity - can accelerate /
    decelerate
  • Can also turn
  • In a ground-based situation, can only turn left
    or right
  • Like a car driving towards a target

10
Forward Movement to a Target
  • At any point in time we want to know
  • Whether to turn left or right, and by how much
  • Whether to accelerate or decelerate
  • Want to reach the target swiftly
  • But avoid excessively large turning circles
  • Worst case circling around the target

11
Turning Dot Product Method
  • Flat surface - use a simple method for turning
  • Assume we have the objects local Z axis (facing
    vector) and we can get the local X axis
  • Extract X-axis it from the objects world matrix
  • If local X unavailable, use this in 2D
  • If Z (a,b), then X (b, -a) in a left handed
    system
  • In 3D can use cross products (c.f. targeting)

12
Turning Dot Product Method
  • Ensure X Z axes are normalised
  • Then get normalised vector, source to target (T)
  • Calculate the angles a and ß using dot products
  • If ß lt 90 then the target is to the right
  • and if ß lt 90 then cos(ß) gt 0, so

13
Turning Dot Product Method
  • Calculate the angle a
  • Indicates how much to turn left or right to face
    target
  • Basic turning method
  • Rotate object (around Y) to turn towards the
    target
  • Rotate by ve angle if cos(ß) gt 0, -ve otherwise

14
Turning Speed
  • Want to turn gradually to face the target
  • Dont want to snap instantly to face it
  • Set a maximum turn speed for the object and cap
    turning by this value
  • I.e. turn by min(turn speed, a)
  • Can consider angular acceleration / deceleration
  • Acceleration to max turn speed when starting to
    turn
  • Deceleration to 0 when almost facing target
  • Similar to the movement acceleration /
    deceleration that follows

15
Acceleration / Deceleration
  • When to accelerate and decelerate?
  • Simple approach
  • The stopping distance is the distance covered
    before stopping if we apply maximum deceleration
  • If the stopping distance is less than the
    distance to the target, then apply maximum
    acceleration
  • Otherwise maximum deceleration
  • If the current speed (not velocity) is s and max
    deceleration d, then
  • Stopping Distance s2 / 2d
  • Since average speed while stopping s / 2
  • And time to stop s / d

16
Practicalities
  • Use this method for static or dynamic tracking
  • When tracking a moving object, consider tracking
    a point in front of it (depending on its speed)
  • Need tweaking
  • Wont target perfectly so stop when within a
    certain range use the length of the target
    vector
  • The stopping distance as given doesnt quite
    match algorithm, should be s2 / 2d s / 2
  • Needs careful insertion into a timed game loop
  • Only use update time when applying movement /
    turning, dont alter angle / stopping distance
    formulae

17
Further Development
  • This is a very basic method, which can easily be
    refined / altered
  • Angular acceleration / deceleration
  • Decelerate to make a sharp turns (when a is
    large)
  • Adapt the acceleration algorithm to consider a
  • Or even smarter acceleration / deceleration /
    maximum speed based on distance and
    manoeuvrability of target
  • Adapt to 3D space use cross products, see Space
    Game entity code or Van Verth p39
Write a Comment
User Comments (0)
About PowerShow.com