What is missing in my game prototype?

Godot Version

Godot 4

Question

I want to create smth very similiar to this game (in the link) so i made some progression but smth is still off.

There is my player code

extends Node2D

@export var orbit_radius: float = 100
@export var orbit_speed: float = 2.0
@export var jump_speed: float = 400

var landed: bool = false 
var orbit_angle: float = 0.0
var orbit_center: Vector2 = Vector2.ZERO
var jumping: bool = false
var jump_target: Vector2 = Vector2.ZERO

func set_orbit_center(pos: Vector2):
	orbit_center = pos
	orbit_angle = 0.0
	jumping = false

func _ready() -> void:
	orbit_center = global_position
	$Area2D.connect("area_entered", Callable(self, "_on_area_entered"))

func _process(delta: float) -> void:
	if jumping:
		var dir = (jump_target - global_position).normalized()
		global_position += dir * jump_speed * delta

		if global_position.distance_to(jump_target) < 10:
			jumping = false
			rotation = orbit_angle + PI / 2
			await get_tree().create_timer(0.1).timeout
			if not landed:
				print("missed, game over")
				get_parent().game_over()
			landed = false
	else:
		orbit_angle += orbit_speed * delta
		global_position = orbit_center + Vector2(orbit_radius, 0).rotated(orbit_angle)
		rotation = orbit_angle + PI / 2
		
func _unhandled_input(event):
	if (event is InputEventScreenTouch and event.pressed) or (event is InputEventMouseButton and event.pressed):
		if not jumping:
			jumping = true
			var jump_vector = Vector2(orbit_radius, 0).rotated(orbit_angle)
			jump_target = global_position + jump_vector.normalized() * 400 
			print("πŸš€ Jumping!")

			

func _on_area_entered(area: Area2D) -> void:
	if jumping and area.get_parent() == get_parent().next_orbit_node:
		print("landed")
		jumping = false
		orbit_center = get_parent().next_orbit_node.position
		get_parent().player_landed_on_orbit((orbit_center))
	

It looks like when you attach to a new circle you snap to an angle of 0.0, which jerks the camera and reorients the triangle. You probably want to determine the attach point and angle based on where the triangle is when it moves into the influence area of the circle, and you probably want to interpolate its position and rotation from the point where it stops jumping to the point where it’s in orbit and attached.

3 Likes

yess! that was the problem, i changed that to this

orbit_angle = (global_position - orbit_center).angle()

and now it works smooth, thanks for help!

1 Like

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