ORilot / DiscordStuff

A little play around with the Webhook feature of discord
0 stars 0 forks source link

Collision functionality - Move() function #44

Open sync-by-unito[bot] opened 5 months ago

sync-by-unito[bot] commented 5 months ago

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:

  1. The traveller calculates its leftToMove according to its MaxVelocity, time passed between frames and TimeStep
  2. the traveller translates its leftToMove to DeltaD
  3. the traveller calls its Move() function

The LateUpdate() function provided by MonoBehaviour() should exhibit this functionality:

  1. remove all instances from the WaitingToMove list

Move() function algorithm:

  1. if the DeltaD is greater than edge left (1-PositionOnEdge) consult Changing Edges below, then GOTO 3
    1. i. e. check whether traveller’s DeltaD is greater than the new edge
  2. check for collisions (see below) at PositionOnEdge + DeltaD
    1. if collision occurs
    2. call registerForMove(this) on the Traveller this has collided with
    3. reduce DeltaD by ((this.positionOnEdge+DeltaD+lengthD)-colliding.PositionOnEdge) where colliding referse to the traveller collided with
    4. then GOTO 4
    5. if no collision occurs
    6. increment PositionOnEdge by DeltaD
    7. reduce leftToMove by DeltaD translated to true distance
    8. then set DeltaD to 0
  3. call Move() on all Travellers in the WaitingToMove list

Changing Edges:

  1. translate edge left (1-PositionOnEdge) to true distance and reduce leftToMove by said distance
  2. call unsubscribe(this) on the edge the traveller is currently on
  3. set PositionOnEdge to 0
  4. call subscribe(this) on the next edge in the traveller’s path
  5. translate length to edge distance and store as new lengthD
  6. recalculate DeltaD with the new leftToMove and edge

Checking for Collisions:

  1. get an iterator for the VehiclesOnRoad list of the edge the Traveller is on
  2. for each entry in the iterator
    1. if this.PositionOnEdge is within the bounds defined by entry.PositionOnEdge and (entry.PositionOnEdge+entry.lengthD) then collision occured
    2. if collision occured, return with the entry
    3. if (this.PositionOnEdge+this.lengthD) is within the bounds defined by entry.PositionOnEdge and (entry.PositionOnEdge+entry.lengthD) then collision occured
    4. if collision occured, return with the entry
  3. if no collission occured yet, return without colliding

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

sync-by-unito[bot] commented 5 months ago

➤ Zdenek Plesek commented:

TODO: