# How to apply speed to my Collision variable?

Godot 4.2

### Question

This is yet Another (but pretty short) question that I have. Basically I’m working on a pong game, and I have a collision variable that’s assigned to a move and collide function with velocity * delta in its parentheses, but It isn’t affected by my speed anymore, Is there anything I’m doing wrong?

``````var collision = move_and_collide(velocity * delta)
``````

Thanks in advance

is velocity multiplied by speed? hard to tell if we do not know the definitions of variables being fed into `move_and_collide`

The variable I made is for something like this:

``````if collision.get_collider().name == "Borders":
hit_sound.play()
``````

I mean how is `velocity` defined and manipulated

Isn’t it a built-in variable?
Or are you talking about something else?

It is a built-in if this is a CharacterBody2D.

How are you manipulating the variable, right now the only equation I know affects your speed is `velocity * delta` I’m pretty sure `delta` is frame time so I need to know what `velocity` contains

It’s a CharacterBody2D

The really important part is `velocity`, I tried to explain it here

How are you manipulating the variable, right now the only equation I know affects your speed is velocity * delta I’m pretty sure delta is frame time so I need to know what velocity contains

I cannot help solve `x = velocity * delta` if I do not know what `velocity = ___`

OH! Now I see what your talking about, Here’s what you’re looking for :

``````func _ready() -> void:
visible = true
var direction = 1
direction = randi_range(1, 4)
if direction == 1:
velocity = Vector2.RIGHT.rotated(PI/4) * speed
elif direction == 2:
velocity = Vector2.LEFT.rotated(PI/4) * speed
elif direction == 3:
velocity = Vector2.LEFT.rotated(PI/-5) * speed
elif direction == 4:
velocity = Vector2.RIGHT.rotated(PI/-5) * speed
``````

I WAS ABLE TO FIX IT, turns out I should have calculated the speed in a physics_process instead of a ready function (because the ready function only happens once while the physics_process constantly updates). Now I can calculate velocity * delta * speed without the game breaking (or in this case, the speed being multiplied and increased constantly with an already fixed speed).

This is the first time I realized my mistake on my own and I hope I can keep on doing this more often, but still thanks @gertkeno for actually making me look into that script a bit more, I highly appreciate it

1 Like