bounce() and reflect() are methods of the Vector2 and Vector3 classes. They are used, respectively, to bounce and reflect vectors off of surfaces.
Information about them can be found in the docs. (See Vector2 and Vector3.)
Linear velocity is usually represented as a vector, and it is normal to call these methods on it in “collision response” code, that is, code describing what to do with velocity after a collision.
Is there a quick example of code that shows an object with linear velocity hitting the screen edge and reflecting off?
ondesic | 2018-03-16 16:25
Use StaticBody2D with collision shapes for walls at the edge of the screen and try something like this:
var collision = collide_and_move(linear_velocity)
if collision:
var normal = collision.normal
var remaining_vel = collision.remainder
remaining_vel.bounce(normal)
collide_and_move(remaining_vel)
I’m not at my computer though and haven’t checked to see if this works though.