+1 vote

So, I'm using motion for player movement and I want to do a spring that pushes the player to a side

I tried using

body.motion.x += pushforce
body.motion = body.move_and_slide(motion,Vector2.UP)

It works, but it pushes instantly rather than in a smooth way, making it look like it was teleported. How it can be smooth?

Godot version 3.2.3
in Engine by (65 points)

1 Answer

0 votes

You can add a property in your player, say momentum: Vector2, and have springs add to it instead of moving the player directly.
Then, inside a _physics_process() you would move the player by momentum using move_and_slide, and then multiply momentum by 0.95 to reduce it progressively, simulating friction.

by (2,684 points)
edited by

And how can I move it with momentum? I need to use move_toward?

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.