This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I want to increase/decrease a CollisionShape2D circle's radius gradually and up to a min/max limit and honestly i have no idea how, trying to use clamp and movetoward but the latter doesn't work with float values (which the radius is)
So is there something like move
toward for float values and if not, then how do i go on about this?
Complete beginner to godot, gdscript and coding in general and just trying to get out of tutorial hell, so go easy on me.
if Input.is_action_pressed("Sprint"): speed = 150 soundBubble.shape.radius = soundBubble.shape.radius.move_toward(8.5, 60.0, 1.0) if Input.is_action_just_released("Sprint"): speed = 90 soundBubble.shape.radius = soundBubble_StandingRadius #want this to be a gradual change as well

Godot version 3.3.2
in Engine by (16 points)

Have you looked into using a Tween?

2 Answers

–1 vote
Best answer

AnimationPlayer can animate any property.

by (887 points)
selected by

Thanks for reminding me, but it wouldn't work for this exact mechanic since multiple actions will be affecting that radius (shooting/running/sneaking) and it would get very messy that way with an animation player.
I simply want to change the radius by a value with an upper/lower limit.
for now i'm using a clamp to keep the radius between two values however its just a band aid solution and i need something like move_toward that i can use with the radius.

Linear interpolation.

Yep, lerp is what i was looking for

I am looking into lerp(), and it is not the same. It requires a weight which goes from 0 to 1 and what I have is the step length, which is the increment per second. I don't know how to do the transformation :/

0 votes

I didn't find a Godot built in solution. This is the implementation that is working for me:

func move_toward(actual:float, to:float, delta:float):
    if(actual < to):
        actual += delta
        actual = min(actual, to)

    return actual
by (69 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.