Test2 FSM Flashcards
Circle / Sphere
πΌπΉ πππ π‘ππππ π = (π₯0 β π₯1) 2 + (π¦0 β π¦1) 2
ππ»πΈπ π 2 = (π₯0 β π₯1) 2 + (π¦0 β π¦1) 2
Collision Occurs IF: (C1 radius + C2 radius) 2 >= (C1x β C2x) 2 + (C1y β C2y) 2
Square/Rectangle
AABB Min-Max
IF (a.Xmax < b.Xmin OR a.Xmin > b.Xmax) return 0 // No Collision Exists IF (a.Ymax < S2MinY OR S1MinY > S2MaxY) return 0 // No Collision Exists return 1 // Collision Exists
Collision Occurs IF: (S1MaxX >= S2MinX AND S1MinX = S2MinY AND S1MinY <= S2MaxY)
Square
AABB Min-Width
Xwidth = | Xmax - Xmin |
Ywidth = | Ymax - Ymin |
IF (a.Xmin β b.Xmin > b.Width OR - (a.Xmin β b.Xmin) > a.Width) return 0 // No Collision Exists
IF (a.Ymin β b.Ymin > b.Width OR - (a.Ymin β b.Ymin) > a.Width) return 0 // No Collision Exists return 1 // Collision Exists
Collision Occurs IF:
(S1MinX - S2MinX) <= S2Xwidth AND - (S1MinX - S2MinX) <= S1Xwidth
AND
(S1MinY - S2MinY) <= S2Ywidth AND - (S1MinY - S2MinY) <= S1Ywidth
Square
AABB Center-Radius
IF ((|a.Xcen - b.Xcen|) > a.rad + b.rad) return 0 // No Collision Exists
IF ((|a.Ycen - b.Ycen|) > a.rad + b.rad) return 0 // No Collision Exists return 1 // Collision Exists
Collision Occurs IF:
( | S1X β S2X | ) <= (S1Radius + S2Radius)
AND
( | S1Y β S2Y | ) <= (S1Radius + S2Radius)
Why Finite State Machines?
Quick and simple to code
easy to debug
they have little computational overhead
intuitive
flexible
What is a FSM?
a device or a model of a device which has a finite number of states it can be in at any given time and can operate on input to either make transitions from one state to another or to cause an output or action to take place. It can only be in one state at a time.
switch based
good for very simple game objects
as more states an donditions are added, thsi sort of structure ends up becoming unreadable and hard to debug.
it makes it hard to code enter and exit conditions
Polymorphic State Machine
Good for more complex code.
easy to code enter and exit condtions
you can embed rules for state changes within each state;