0 votes

am trying to add a spring to my game but i dont know the way to do it can someone
pls explain to me

in Projects by (161 points)

1 Answer

+1 vote
Best answer

You can add an Area2D to a spring sprite. And use the on Body entered signal

After you connect it. It should create a function on your object script( this will work if you have a script connected to the player, and you only want one thing to jump)
A function will be created called:


Inside this you can use get_position to get the objects position.

Before anyone can help you further we need more info what is the spring going to be used for is it for a pinball machine. To help the player jump to platforms. What kind of physics is the player using.

When asking for help always be specific, as people's help is limited to how specific you are.

by (160 points)
selected by

thanks for answering
i need the spring for a platformer game pls is there anything i need to take note of

I see. I created a function that should if the player is a KinematicBody2D make it so anytime it collides with a CollisionBody jumps in the air. This works fine with any staticbody but for some reason it didn't quite work for me with Area2D. At any rate
use this in a your function that does the updating

if get_slide_count() > 0 :
move_and_slide(velocity, Vector2(0,-1))

JUMP is a constant and should be negative since the up direction is negative.
I'm hoping this will help you get started.

I am still somewhat new to godot, and a bit busy at the moment. This should help however good luck.

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 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 webmaster@godotengine.org with your username.