+1 vote

extends KinematicBody2D

const SHOOT_VELOCITY = Vector2(800, -400)

var velocity = Vector2.ZERO

func ready():
set
physics_process(false)

func launch(direction):
velocity = SHOOTVELOCITY * Vector2(direction, 1)
set
physics_process(true)

func physicsprocess(delta):
if Input.isactionjustpressed("attack"):
var Player = load("res://Player/Player.tscn")
var GreenBullet = load("res://Bullets/GreenBullet.tscn")
var greenBullet = GreenBullet.instance
greenBullet.x = Player.x
greenBullet.y = Player.y
var collision = move
andcollide(velocity * delta)
if collision != null:
queue
free()

Godot version Godot Engine v3.3.stable.official
in Engine by (24 points)

2 Answers

+1 vote

so im newer to the engine, but I can see what's wrong.

greenbullet.x = player.x and greenbullet.y = player.y means that you're teleporting the sprite over to the player, at least thats what I think.

what I would do (I dont know gdscript so well, I do python but you can probably figure out what I mean) is this:

if greenBullet.x > player.x:
greenBullet.x + 10 (or 20 or however many pixels you want)
elif greenBullet.x < player.x:
greenBullet.x - 10 (or 20 or however many pixels you want).
else:
greenBullet.x = greenBullet.x

do the same thing but replace x with y, and maybe that might work. not trying it out in Godot myself, but yeah.

by (16 points)
+1 vote

im also not that far, but i watched a ton of videos the last days to get a feeling.

https://www.youtube.com/watch?v=isA7P9ulBwE

i remember this one from yesterday, he is showcasing and at one point talking about the projectile velocity.

this should give a an idea for a working approach i guess.

hope this helps in finding a solution :)

by (40 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.