2D Minigolf Physics

Godot Version

4.3

Question

I’m trying to make a golf style game, but I don’t exactly know how to make the pull and release golf physics that I want for the game. Anyone know how I could go about this?

you have to explain the mechanic you want, we can’t read your mind.

make a drawing or try to describe what you want. it won’t just help us help you, it can also allow you to see it more clearly and get closer to a solution on your own.

Give me just a second

Here’s the basic idea that I’m thinking of, apologies for not including the doodle initially

no problem, this isn’t a chat, you can take your time and others will do so as well.

what I see there is that the left click is held and drag back, and at one point you either release the button or a threshold is pass.

usually for this we start when the mouse button is pressed, and when the button is released we calculate the distance between the position of the cursor to the ball.
we then use the result to calculate the force or speed of the ball.

so start on input or process:

var launch_force : float = 0.0
var start_pos : Vector2

func _process(delta) -> void:
	if Input.is_action_just_released("Left_click"):
		launch_force = start_pos.distance_to(get_viewport().get_mouse_position())
	elif Input.is_action_just_pressed("Left_click"):
		start_pos = get_viewport().get_mouse_position()

then you would have to transform or normalize the launch_force to a value that can be used, and apply it to the ball.

I ended up tweaking this just a bit but for the most part this works! Thank you so much

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.