Hi! I'm currently following GDQuest's tutorial on a vampire survivors like top down shooter (https://www.youtube.com/watch?v=GwCiGixlqiU&t=4011s), and I am trying to make my own modifications. What I'm trying to do the most is to make it so the gun points towards your mouse and shoots when you click. I've got most of the systems working, but the big issue I'm facing is that the bullets always move in the direction of the mouse. What I want is for the bullets to always move forward in a straight line in whatever direction they were shot and and not move with the mouse. Please help!
Gun script:
extends Area2D
var firerate = 45
var shotdelay = 0
const BULLET = preload("res://Scenes/bullet.tscn")
@onready var shootingpoint = %ShootingPoint
func _physics_process(delta: float):
look_at(get_global_mouse_position())
if Input.is_action_just_pressed('shoot'):
shoot()
shotdelay -= 1
func shoot():
var new_bullet = BULLET.instantiate()
%ShootingPoint.add_child(new_bullet)
new_bullet.global_transform = %ShootingPoint.global_transform
Bullet Script:
extends CharacterBody2D
var speed = 1000
var distance = 0
var lifetime = 1200
var dir: float
func _physics_process(delta: float):
velocity = Vector2(speed, 0).rotated(dir)
move_and_slide()
if distance > lifetime:
queue\_free()
func _on_body_entered(body):
queue_free()
if body.has_method("takedamage"):
body.take\_damage()
r/godot - 2D top down shooter bug
r/godot - 2D top down shooter bug