This feature extends and replaces the current Move() functionality of the Traveller class.
The high-level overview is as follows: the traveller attempts to move when their Update() function, (inherited from the MonoBehvaiour class) gets called. If they encounter a different traveller at the position they wish to move to, they move up as far as they can and then let the blocker know to notify them in case it [the blocker] moves. If the blocker moves, the car moves up the rest of their movement. At the end of the frame, all requests to be notified in case of move are discarded.
To achive this functionality the traveller class is extended with the following private attributes:
float leftToMove
the distance the traveller still has left to move
float length
the segment of road this traveller occupies
specified during Traveller initialisation, default 0
float lengthD
traveller’s length in terms of the road it is on
recalculated each time Traveller enters new Edge
WaitingToMove
linked list of Traveller class
initialised to an empty linkedList
static float TimeStep
represents the ratio between the real time passed and time passed in simulation
The traveller class needs to be extended with the following Public method:
registerForMove(Traveller)
this function adds the Traveller passed to the WaitingToMove linked list
The function OnUpdate() provided by mono behaviour should exhibit this functionality:
The traveller calculates its leftToMove according to its MaxVelocity, time passed between frames and TimeStep
the traveller translates its leftToMove to DeltaD
the traveller calls its Move() function
The LateUpdate() function provided by MonoBehaviour() should exhibit this functionality:
remove all instances from the WaitingToMove list
Move() function algorithm:
if the DeltaD is greater than edge left (1-PositionOnEdge) consult Changing Edges below, then GOTO 3
i. e. check whether traveller’s DeltaD is greater than the new edge
check for collisions (see below) at PositionOnEdge + DeltaD
if collision occurs
call registerForMove(this) on the Traveller this has collided with
reduce DeltaD by ((this.positionOnEdge+DeltaD+lengthD)-colliding.PositionOnEdge) where colliding referse to the traveller collided with
then GOTO 4
if no collision occurs
increment PositionOnEdge by DeltaD
reduce leftToMove by DeltaD translated to true distance
then set DeltaD to 0
call Move() on all Travellers in the WaitingToMove list
Changing Edges:
translate edge left (1-PositionOnEdge) to true distance and reduce leftToMove by said distance
call unsubscribe(this) on the edge the traveller is currently on
set PositionOnEdge to 0
call subscribe(this) on the next edge in the traveller’s path
translate length to edge distance and store as new lengthD
recalculate DeltaD with the new leftToMove and edge
Checking for Collisions:
get an iterator for the VehiclesOnRoad list of the edge the Traveller is on
for each entry in the iterator
if this.PositionOnEdge is within the bounds defined by entry.PositionOnEdge and (entry.PositionOnEdge+entry.lengthD) then collision occured
if collision occured, return with the entry
if (this.PositionOnEdge+this.lengthD) is within the bounds defined by entry.PositionOnEdge and (entry.PositionOnEdge+entry.lengthD) then collision occured
if collision occured, return with the entry
if no collission occured yet, return without colliding
Dependency: https://trello.com/c/TvIBv6JPhttps://trello.com/c/GjnMYVWY
This feature extends and replaces the current Move() functionality of the Traveller class.
The high-level overview is as follows: the traveller attempts to move when their Update() function, (inherited from the MonoBehvaiour class) gets called. If they encounter a different traveller at the position they wish to move to, they move up as far as they can and then let the blocker know to notify them in case it [the blocker] moves. If the blocker moves, the car moves up the rest of their movement. At the end of the frame, all requests to be notified in case of move are discarded.
See https://trello.com/c/GjnMYVWY for functions that translate true distance into edge distance and the inverse.
To achive this functionality the traveller class is extended with the following private attributes:
The traveller class needs to be extended with the following Public method:
The function OnUpdate() provided by mono behaviour should exhibit this functionality:
The LateUpdate() function provided by MonoBehaviour() should exhibit this functionality:
Move() function algorithm:
Changing Edges:
Checking for Collisions:
Specified by: Zdenek Plesek
Implemented by: Zdenek Plesek
Validated by:
┆Issue is synchronized with this Trello card by Unito ┆Attachments: Collision-implementation | #42 Collision implementation