![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | ZENAJ |
Hello there, I just want to say that I’m extremely new to Godot and still am trying to find my way into game development. Thus I started developing a small game in which an arrow rotates approx 180 degrees around an origin point at the bottom of the screen, while having to jump around to dodge incoming platforms. At the moment I’m failing a little at properly getting my sprite to jump “away” from the origin point rather than just vertically upwards. I’ve provided the code in its current state below:
var rotation_speed = 90 # Adjust the rotation speed as desired
var rotation_direction = 0 # defines the default state of rotation direction
var jumping = 0 # defines the default state of jumping
var jump_speed = 500 #defines the speed of the jump animation
var jump_height = 0 #defines the default state of height of jump
var jump_distance = 200 # Adjust the jump distance as desired
const MAX_ROTATION = 75 # defines the maximal range of rotation
var forward_vector = Vector2.ZERO #defines the nul state of the x and y vector (0,0)
var vertical_velocity = 0 # defines the default state of vertical_velocity
const GRAVITY = 2000 # Adjust the gravity strength as desired
var dpoint = Vector2(100,0)
func _process(delta):
rotation_angle += rotation_speed * rotation_direction * delta
rotation_angle = clamp(rotation_angle, -MAX_ROTATION, MAX_ROTATION) #
sets the margins in both directions
if jumping:
vertical_velocity -= GRAVITY * delta
jump_height += vertical_velocity * delta
if jump_height <= 0:
jump_height = 0
vertical_velocity = 0
jumping = 0
self.rotation_degrees = rotation_angle
self.position.y = (jump_height*-1)
func _input(event):
if event is InputEventKey:
if event.is_action_pressed("rotate_left"):
rotation_direction = -1 # Rotate left
elif event.is_action_pressed("rotate_right"):
rotation_direction = 1 # Rotate right
elif event.is_action_pressed("jump") and not jumping:
jumping = 1
vertical_velocity = jump_speed
if event is InputEventKey:
if event.is_action_released("rotate_left") and rotation_direction == -1:
rotation_direction = 0 # Stop rotation
if event.is_action_released("rotate_right") and rotation_direction == 1:
rotation_direction = 0 # Stop rotation
I’ve also tried to utilize:
var dpoint = Vector2(100,0)
position = dpoint + (position - dpoint).rotated(rotation_angle)
but that just caused a weird jittery glitch when my sprite jumps.
if anyone has something that can give me a clue on how to fix it (or perhaps critique on my code), it’d be much appreciated.