This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

In my program I create bullet instances at the player's weapon, but these instances aren't move.
Here the code where I create bullets:

extends Sprite

var bullet=preload("res://robflovedeke.tscn")
var dir=Vector2()

func process(delta):
if get
dir = (getglobalmouse_position()-self.position).angle()+180

if (Input.is_mouse_button_pressed(BUTTON_LEFT)):
    var l=bullet.instance()

And the other code in the bullet node:

extends KinematicBody2D

var itsspeed = 4

func physicsprocess(delta):
var collideobj=moveandcollide(Vector2(-itsspeed*delta,0))
if position.x<get_viewport_rect().size.x/2: #get_viewport().size/2
elif (collideobj):
if collideobj.get_collider()=="ellenseg":

Bullets are created well, but not moving. What is wrong with my code?

Godot version 3.3 Stable Official Win64
in Engine by (52 points)

4*delta is 4 pixels per second. Are you sure it's not moving at all and not just moving very slowly? Increase itsspeed to 400 and see if that helps.

dir = (getglobalmouse_position()-self.position).angle()+180
angle() returns radians and the rotation propery expects radians, you need to deg2rad(180) to make this work how you want it to

I increased "itsspeed" variable, but the situation is the same: the bullet is created on the weapon sprite and doesn't move.
I thought it is because of collision between bullet and weapon, therefore I changed initial position X and Y values of bullet onto a collison free place, but the bullets are stand in one place. :-/

Please log in or register to answer this question.

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.