I'm making a spaceshooter game and I want my Character (Spaceship) to move towards and rotate to the mouse when I press "ui_up" and moving away when I press "ui_down"

Non-topic:
I was watching youtube tutorials for a long time and now I realized that all of this was a waste of time 👿. Now I only have a little experience of godot like I can make basic Input Actions. 😞

Should I continue this project untill the end? (If I reach it at the end I will post it)

Yes100%
No0%
  • DaveTheCoder replied to this.
  • About tutorials, tutorial hell is a thing. Finishing a game by yourself, no matter how small it is, is a confidence boost in you abilities, and makes you less dependent on tutorials.
    Now for the spaceship movement, whenever I try to code features alone without tutorials I like to take the smallest baby steps possible.
    For example:
    1) I will print "up" when i press "ui_up" and "down" when i press "ui_down"
    2) Insted of printing "up" or "down", print mouse position
    3) Now that I know how to get the mouse position, I will print a direction vector from the spaceship position to the mouse position. A neat way to do it is using the some_vector.direction_to(other_vector) function.
    4) Great, let's try to move the ship by doing this and this and this.
    5) I might have problems, this doesn't work as expected so let's redo the movement step by step, I would visit the docs and see how this node works. What type does this function return and what does this function do.
    6) Now that the ship moves, let's rotate it. Once again I'd visit the docs and see how angle() and other Vector2 stuff work. After experimenting the ship rotates!
    7) Now there are only some small problems, that might require an extra if statement or an extra condition to a pre-existing one, maybe resetting a variable every frame, or calculating something in the wrong place in code.
    With practice, repetition, and experience, I believe the wholr process becomes shorter.

    Code in spoiler just in case:

    
    >! var speed = 300.0
    >! var angle_correction_in_radians = PI/2 # 90 degrees, tweak this so the ship really faces the player
    >! func _physics_process(delta):
    >!     velocity = Vector2.ZERO
    >!     var direction = global_position.direction_to(get_viewport().get_mouse_position())
    >!     if Input.is_action_pressed("ui_up"):
    >!         velocity = direction * speed * delta
    >!     elif Input.is_action_pressed("ui_down"):
    >!         velocity = - direction * speed * delta
    >!     rotation = direction.angle() + angle_correction_in_radians
    >!     move_and_slide()

    Edit: I dont know how to use spoiler tags!

    Meternik I was watching youtube tutorials for a long time and now I realized that all of this was a waste of time

    Watching tutorials is fine, but you should spend at least as much time writing your own code.

    About tutorials, tutorial hell is a thing. Finishing a game by yourself, no matter how small it is, is a confidence boost in you abilities, and makes you less dependent on tutorials.
    Now for the spaceship movement, whenever I try to code features alone without tutorials I like to take the smallest baby steps possible.
    For example:
    1) I will print "up" when i press "ui_up" and "down" when i press "ui_down"
    2) Insted of printing "up" or "down", print mouse position
    3) Now that I know how to get the mouse position, I will print a direction vector from the spaceship position to the mouse position. A neat way to do it is using the some_vector.direction_to(other_vector) function.
    4) Great, let's try to move the ship by doing this and this and this.
    5) I might have problems, this doesn't work as expected so let's redo the movement step by step, I would visit the docs and see how this node works. What type does this function return and what does this function do.
    6) Now that the ship moves, let's rotate it. Once again I'd visit the docs and see how angle() and other Vector2 stuff work. After experimenting the ship rotates!
    7) Now there are only some small problems, that might require an extra if statement or an extra condition to a pre-existing one, maybe resetting a variable every frame, or calculating something in the wrong place in code.
    With practice, repetition, and experience, I believe the wholr process becomes shorter.

    Code in spoiler just in case:

    
    >! var speed = 300.0
    >! var angle_correction_in_radians = PI/2 # 90 degrees, tweak this so the ship really faces the player
    >! func _physics_process(delta):
    >!     velocity = Vector2.ZERO
    >!     var direction = global_position.direction_to(get_viewport().get_mouse_position())
    >!     if Input.is_action_pressed("ui_up"):
    >!         velocity = direction * speed * delta
    >!     elif Input.is_action_pressed("ui_down"):
    >!         velocity = - direction * speed * delta
    >!     rotation = direction.angle() + angle_correction_in_radians
    >!     move_and_slide()

    Edit: I dont know how to use spoiler tags!

      BroTa I dont know how to use spoiler tags!

      It doesn't work here. Or rather, it works in a very specific way. 😃

      Spoiler!

      BroTa Edit: I dont know how to use spoiler tags!

      don't put a codeblock in spoiler, it's already size limited and will get a scrollbar if the codeblock is longer than the div size it's inside of so overflow isn't really an issue.

      BroTa I dont know how to use spoiler tags!

      It seems to be:

      >!hide!<

      hide

      And if so:

      >!hide

      Click to reveal Click to hide

      hide