0 votes

I created one and I put it in the middle of the screen, but it doesn't work

extends Node2D

var shape
var bullet

class Bullet:
    var pos = Vector2()
    var body = RID()

func _draw():
    var t = preload("res://bullet.png")
    var tofs = -t.get_size()*0.5
    draw_texture(t, bullet.pos + tofs)

func _process(delta):

func _ready():
    var grivaty = Physics2DServer.area_get_param(get_world_2d().get_space(),Physics2DServer.AREA_PARAM_GRAVITY_VECTOR)

    bullet = Bullet.new()
    bullet.body = Physics2DServer.body_create()

    shape = Physics2DServer.circle_shape_create ()
    Physics2DServer.shape_set_data(shape, 8)
    Physics2DServer.body_set_space(bullet.body, get_world_2d().get_space())
    Physics2DServer.body_add_shape(bullet.body, shape)

    bullet.pos = get_viewport_rect().size/2
    var mat = Transform2D()
    mat.origin = bullet.pos
    Physics2DServer.body_set_state(bullet.body, Physics2DServer.BODY_STATE_LINEAR_VELOCITY, mat)

  • Edited for clarity. ~Avencherus
in Engine by (24 points)
edited by

Also, wouldn't it be a lot easier if you just made a bullet scene then instance and spawn bullets wherever you need them?

This is just a test that my goal is to create a large number of rigibody2d like objects

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.