Creating a Spring

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By code

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

:bust_in_silhouette: Reply From: ZBot

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.

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

code | 2018-08-08 09:11

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.

ZBot | 2018-08-09 14:54