Danilo Jonić
Danilo Jonić

Reputation: 111

I am a newbie who wants to make a game

I started my game dev journey in Godot. I have an issue, I am making a Google Dino / Geometry Dash lookalike game that includes a flat surface (for now), color gates (checkpoints in red, green and blue) and a player who is a triangle.

On user input (LMB or SPACEBAR at the moment), the triangle should rotate -120 degrees landing on a specific color so it can pass through the oncoming 'color checkpoint'.

I started with AnimationPlayer but have switched to Tweens as I figured out they should give me more control over the animation. The issue is that the pivot point doesn't change after the first rotation but rather goes 'below' the imaginary surface and that's it meaning on 4 inputs it completes a rotation around the original pivot point. The entire code in GDScript for Player is down below. Also, on every animation input it seems to 'artificially' moves slightly backwards which makes no sense. I am new to this and really have no idea what I am doing or how to fix it. I spent hours troubleshooting it and still haven't moved on to actually making the background surface and the color checkpoints.

enter image description here

extends CharacterBody2D

var tween: Tween
var side_length = 50  
var rotation_angle = -120  
var current_rotation = 0  

func _input(event):
    if event is InputEventKey and event.pressed and event.keycode == KEY_SPACE:
        start_roll()

    if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
        start_roll()

func start_roll():
    if tween and tween.is_running():
        return  

    
    current_rotation += rotation_angle

    
    var pivot_offset = Vector2(-side_length / 2, side_length * sqrt(3) / 6)
    var pivot_point = position + pivot_offset.rotated(deg_to_rad(current_rotation - rotation_angle))

    
    var new_pivot_offset = pivot_offset.rotated(deg_to_rad(current_rotation))
    var new_position = pivot_point - new_pivot_offset

    
    tween = create_tween()
    tween.set_parallel(true) 

    
    tween.tween_property(self, "rotation_degrees", current_rotation, 0.5) \
        .set_trans(Tween.TRANS_SINE) \
        .set_ease(Tween.EASE_IN_OUT)

    
    tween.tween_property(self, "position", new_position, 0.5) \
        .set_trans(Tween.TRANS_SINE) \
        .set_ease(Tween.EASE_IN_OUT)
 

    tween.tween_property(self, "position", new_position, 0.5) \
        .set_trans(Tween.TRANS_SINE) \
        .set_ease(Tween.EASE_IN_OUT)

Upvotes: 1

Views: 28

Answers (0)

Related Questions