Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Sigmoid function to GDScript. #12

Open
8bitprodigy opened this issue Oct 3, 2024 · 11 comments · May be fixed by Redot-Engine/redot-engine#148
Open

Add a Sigmoid function to GDScript. #12

8bitprodigy opened this issue Oct 3, 2024 · 11 comments · May be fixed by Redot-Engine/redot-engine#148

Comments

@8bitprodigy
Copy link

8bitprodigy commented Oct 3, 2024

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
Copy link

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
Copy link
Author

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
Copy link

muhuk commented Oct 4, 2024

Please refrain using ALL CAPS in issue titles.

@heppocogne
Copy link

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

@EndsM
Copy link

EndsM commented Oct 4, 2024

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
Copy link
Author

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
Copy link
Author

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.

@Redot-Engine Redot-Engine deleted a comment Oct 6, 2024
@digimbyte
Copy link

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
Copy link

Does this have a related Godot proposal issue?

@Spartan322 Spartan322 changed the title FEATURE REQUEST/PROPOSAL: Add a Sigmoid function to GDScript. [Proposal] Add a Sigmoid function to GDScript. Oct 14, 2024
@SkogiB
Copy link

SkogiB commented Oct 14, 2024

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
Copy link

Spartan322 commented Oct 14, 2024

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.

@Spartan322 Spartan322 changed the title [Proposal] Add a Sigmoid function to GDScript. Add a Sigmoid function to GDScript. Oct 17, 2024
@Spartan322 Spartan322 transferred this issue from Redot-Engine/redot-engine Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants