User Tools

Site Tools


4rpl:commands:bounceedgecollision

Index

BounceEdgeCollision

BounceEdgeCollision(<-currentPosition <-lastPosition <-reflectionScale) ->newLastPosition ->newPosition

Description

Calculates a bounce off of the edge of the map. Given two positions that represent the current and previous positions of a moving object, this call will calculate a new position and previous position for the moving object. The new positions will calculate a colllision with any mape edge and generate a reflection so that the moving object will appear to have bounced off of the edge.

  • currentPosition: A vector for the current position of a moving object
  • lastPosition: A vector for the last position of a moving object. The currentPosition-lastPosition is used to determine a vector of motion for the object.
  • reflectionScale: A float that controls the scale of the reflection. A value of 1 makes the reflection the same as the input velocity. A value less than 1 damps the reflection and a value greater than 1 amplifies the reflection.

Note that if there is no edge collision then the 'w' (the last) position in the resulting vectors will be 0 (false). It will be 1 if there was a collision. Also note that if there is no terrain collision then the resulting newPostion and newLastPosition will be equal to currentPosition and lastPosition.

Examples

BounceEdgeCollision(<-position, <-lastPosition, 1) ->nlp ->np
if (<-np.w)
   <-np ->position
   <-nlp ->lastPosition
endif

Index

4rpl/commands/bounceedgecollision.txt · Last modified: 2021/01/08 11:01 by 127.0.0.1