+1 vote

The control of my game should be holding left click to display circles that, depending on how far of the character it's the mouse position, it would appear just one circle or a row of circles one bigger than the other (to mark the strengh to which the player will speed burst) and when released, the char applies that force, bounce if there's a collision while being in middle of that impulse and then stops smoothly.
I.e: like a slingshot.

in Engine by (122 points)
retagged by

any reason you're using a kinematic body vs a rigid body? a rigid body might be easier to slingshot but if its not what your going for thats totally fine.

Hi! Sorry, i confused rigid body with move and collide(), i'll fix that.
My game it's 2D.

1 Answer

0 votes
Best answer

Here's my code.

extends RigidBody2D

var speed = 1

func _physics_process(delta):
var mouse_position = get_global_mouse_position()

var sling_direction = mouse_position - self.position 

if Input.is_action_just_released("slingshot"):
    set_linear_velocity(sling_direction * speed)

While this doesn't have rings which change the speed, it does have more speed depending on how far the mouse is from the player. Hope this helps!

by (391 points)
selected by

Thanks! Just would had been good to spawn an arrow that strecth more or less depending on how far the mouse position it's but mechanic's the most important part so thank you again!

just find the distance between the player and the mouse position and multiply it times your speed variable. should do the trick! :)

oh, didn't read your comment carefully enough. Thought you were saying you wanted it to slow faster depending on your mouse position like you did with your movement. :)

Unfortunately If I was trying to make that type of arrow, I would probably end up asking on this site, so it wouldn't help you much. lol.

Doesn't matter so much. Thanks for your accidental advice in how to slow the player faster depending in it's velocity! XD

np. Actually when I look back, you should probably multiply the distance by the deceleration value. I got the variable name wrong. :)

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.