how to change speed while bouncing

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By roxy248324

well, i don’t know if the title is right, i don’t speak english and i’m translating through google translator

but my question is this, in my project the bullets are losing speed until they reach 0, but i also want the bullets to bounce off the wall, to do this i’m using kinematicbody2d and guiding myself through the documentary:

extends KinematicBody2D

var speed = 750 var velocity = Vector2()

func start(pos, dir):
rotation = dir
position = pos
velocity = Vector2(speed, 0).rotated(rotation)

func _physics_process(delta):
var collision = move_and_collide(velocity * delta)
if collision:
velocity = velocity.bounce(collision.normal)

but doing this has no way to slow down the bullet, I have no idea how to do this, please could someone help me? I’ve been breaking my head for hours

:bust_in_silhouette: Reply From: Lopy

You can use a velocity = velocity * 0.95 in you _process to have it slow down over time, of a velocity = velocity * 0.6 if you use it when collisions happen. The shorter writting is velocity *= .95.

Automatic translation has gotten pretty good.