#Limit Vector2

15 messages · Page 1 of 1 (latest)

quiet sparrow
#

Hi, I'm a beginner to Godot.
This is my code:

if abs(velocity.x) > TERMINAL_VEL.x:
    velocity.x = sign(velocity.x) * TERMINAL_VEL.x
if abs(velocity.y) > TERMINAL_VEL.y:
    velocity.y = sign(velocity.y) * TERMINAL_VEL.y

I haven't worked with Vector2s much, but there must be a shorter way to do this? I've used my previous knowledge of programming to do this.

rain wave
#

You should be able to do velocity = velocity.limit_length(TERMINAL_VEL)

#

Also was this posted 3 times?

quiet sparrow
#

no

#

dont think so

rain wave
#

That's so weird

quiet sparrow
#

ohh it was weird i was trying to post it but it kept on loading

#

for me it shows up only once

quiet sparrow
#

i think limit length only accepts floats

rain wave
#

Ohhh

#

Sorry, I see what you're trying to do.

#

Try velocity = velocity.clamp(-TERMINAL_VEL, TERMINAL_VEL)

quiet sparrow
#

my bad i should have provided more context