Redot-Engine / redot-proposals

Redot Improvement Proposals
MIT License
33 stars 8 forks source link

Add a Sigmoid function to GDScript. #12

Open 8bitprodigy opened 1 month ago

8bitprodigy commented 1 month ago

Tested versions

N/A

System information

N/A

Issue description

The sigmoid function is one that follows a roughly S-shaped curve, asymptotically reaching an upper and lower bound. Such a function would work great for weapon sway wherein the magnitude of the mouse/joystick movement is mapped to a position determined through the sigmoid function.

Steps to reproduce

N/A

Minimal reproduction project (MRP)

Here is a GDScript implementation of the sigmoid function:

func sig(x : float, amplitude : float, y_translate : float):
    return ( (amplitude) / (1 + exp(x)) ) + y_translate
digimbyte commented 1 month ago

I think this and many other functions can be bundled in a Math or a Noise class 100% viable, but should account for other similar functions

8bitprodigy commented 1 month ago

I think this and many other functions can be bundled in a Math or a Noise class 100% viable, but should account for other similar functions

Oh, absolutely, and GDScript already has functions like sin(), cos(), and tan(), and they could be included alongside those.

muhuk commented 1 month ago

Please refrain using ALL CAPS in issue titles.

heppocogne commented 1 month ago

There's a S-shaped curve preset in Curve resource (not sigmoid). This would work for value mapping. image

EndsM commented 1 month ago

There's a S-shaped curve preset in Curve resource (not sigmoid). This would work for value mapping. image

Bézier curve is not a Sigmoid function, it can looks like that, but is not calculated that way. Adding a Sigmoid function can be useful, but there are sign() function already, may need to consider the possibilities of confusion

8bitprodigy commented 1 month ago

but there are sign() function already, may need to consider the possibilities of confusion

Well, maybe the builtin function could be named sigmoid() instead of sig().

8bitprodigy commented 1 month ago

There's a S-shaped curve preset in Curve resource (not sigmoid). This would work for value mapping.

Bezier curves do not approach their bounds asymptotically, whereas sigmoid functions do. This means that the higher the value you plug into a sigmoid, the closer it reaches the bound, but without touching -- for the bezier curve, it will reach that limit. For something like weapon sway, that will create an effect where the model's movement appears to hit a wall, whereas a sigmoid function will appear to meet greater and greater resistance.

digimbyte commented 1 month ago

makes sense, sort of like an ease-in and ease-out. as for the curve, value mappings are inherently slower due to the cross point lookup, it can work but a raw math is superior

Spartan322 commented 1 month ago

Does this have a related Godot proposal issue?

SkogiB commented 1 month ago

Does this have a related Godot proposal issue?

No results for "sigmoid" in issues or PRs, open or closed. Seems like fair game for us

Spartan322 commented 1 month ago

I kinda would like this to be thrown upstream first, but that would depend on what @8bitprodigy wants, or in the case of Redot-Engine/redot-engine#148 what @NickUfer also wants, if they don't want it upstream then we'll need to merge it in a way to minimize merge conflicts with Godot.

8bitprodigy commented 4 weeks ago

I kinda would like this to be thrown upstream first, but that would depend on what @8bitprodigy wants, or in the case of Redot-Engine/redot-engine#148 what @NickUfer also wants, if they don't want it upstream then we'll need to merge it in a way to minimize merge conflicts with Godot.

Whatever works for y'all.

SkogiB commented 3 weeks ago

I kinda would like this to be thrown upstream first, but that would depend on what @8bitprodigy wants, or in the case of Redot-Engine/redot-engine#148 what @NickUfer also wants, if they don't want it upstream then we'll need to merge it in a way to minimize merge conflicts with Godot.

Whatever works for y'all.

I posted on the PR for this, we revised this policy as a team due to a bunch of concerns. I need to check on the PR, we were just waiting on some small changes and then a squash afterwards iirc

8bitprodigy commented 3 weeks ago

I posted on the PR for this, we revised this policy as a team due to a bunch of concerns. I need to check on the PR, we were just waiting on some small changes and then a squash afterwards iirc

He'll yeha!