#2D top down shooter bug

1 messages · Page 1 of 1 (latest)

vestal minnow
#

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

solar sandal
#

[]cb

late zenithBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ``` (3 backticks. Click here to see where the key is)

To use syntax highlighting, add the file extension of the language you wish to highlight (cs for C#, cpp for C++)

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

solar sandal
#

because children nodes are positioned relative to their parents

vestal minnow
#

ok

#

fixed, changed the bullets to toplayer

solar sandal
#

still shouldn't be the player