Last active
November 10, 2020 13:36
-
-
Save lucasvanmol/d8fc13c74f43d24b9e77a210e3874d07 to your computer and use it in GitHub Desktop.
Godot script describing the motion of a damped oscillator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extends Sprite | |
| var displacement := 0.0 | |
| var velocity := 0.0 | |
| export (float) var spring_constant := 150.0 | |
| export (float) var damp_constant := 5.0 | |
| func _process(delta): | |
| var force = -spring_constant * displacement + damp_constant * velocity | |
| velocity -= force * delta | |
| displacement -= velocity * delta | |
| material.set_shader_param("STRENGTH", displacement) | |
| if Input.is_action_just_pressed("ui_accept"): | |
| velocity = 20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment