Need help interpolating vairable to vector3.Up when needed

Need help interpolating Vector3 vairable to Vector3.Up when needed

I need to interpolate my Vector3 “Norm” to Vector3.Up vairable once recorecting is true.
It only interpolates to the Vector3.Up only just a little and never finishes even when the recorecting vairable is equal true the code is at the botom for the vairable.

Can some one please help me I really need to clean this ground detection up so I can make my character controller modular :slightly_frowning_face:

Could you explain further what you want this to do? What you expect to happen versus what really happens?

It will only give one value, linear interpolation, or lerp is a short math function as follows

float lerp(float a, float b, float weight) {
    return a + (b - a) * weight;
}

If Recorreccting is true this will take a mid-point (0.5 is middle, 1.0 would be exactly Vector3.UP) of the collision normal and the Vector3.UP.

1 Like

Sure! so this is supposed to be the ground normal vairable for the my ground detection return function and I want it to be equal to the raycast normal if recorecting is equal to false but if it is equal to true then interpolate back Vector3.Up. And that mid point thing you were talking about makes sense now that I’m thinking about it

Also does this mean that I would have to make my own lerp function that interpolates from the ground normal to Vector3.Up

if you are trying to do this over time, then you should try to use a Tween. Or if the tween would be interrupted often, store the weight portion of the lerp as a variable, and increase it over time.

I do not understand the full scope of this yet, but maybe you want a “landed” variable to keep track of how long they have been on the ground, then use that “landed” timer as the weight?

I don’t see a refference for tweens that let me tween a float to another or I’m just not looking hard enough I don’t know. I don’t know how I would tween a float. Could you tell me how I would do that type of stuff cause I can’t find out how on google.

In Godot 3 a Tween is a node type, you can look inside the editor documentation by right-clicking a created Tween node, or hitting F1 and searching for Tween.

I believe you want to tween a Vector3 type, the example in the documentation is for a Vector2, but it will work the same for 3 components.

var tween = get_node("Tween")
tween.interpolate_property($Node2D, "position",
        Vector2(0, 0), Vector2(100, 100), 1,
        Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
tween.start()

I don’t see any thing in the doc that say’s that you can interpolate a vector3 vairable with in a script. Maybe there’s another way I could interpolate the vairable by making a custom function maybe? or I I’m just wrong and maybe you can actually interpolate a vector3 vairable in a script and I didn’t look hard enough… some times that happens with me

You can absolutely interpolate a Vector3, it takes a Variant type for the start and end position, which can be anything; it will throw an error if it can’t interpolate the given Variant.

A normal may behave poorly (length may not always equal 1), depends on what you intend to do with the interpolated normal.

would I be able to use TweenMethod function to interpolate the vector3 and if so how would I have to go along with doing that because I can’t seem to understand this method thing.

Here i’ve transformed the example to use Vector3s,

Since you are using C# it will be different; but the basic flow is:

  1. Create a tween node
  2. Find your starting position and ending position (collision normal and Vector3.UP)
  3. Use the tween to call InterpolateProperty with your starting and ending position
  4. remember to call tween .Start()

I have never heard of TweenMethod but you absolutely can use Tween to interpolate a vector 3.

ok I’ll try it and let you know how it goes


I do not know how I’m supposed to tween this Vairable if the Vairable is required to be a nodepath.

The node path is the property in quotes

"gravity"

This doesn’t look like I would expect it to, are you using Godot 4?

no I’m using godot 3.5