0 votes
extends RigidBody2D

export var min_value := 0.0
export var max_value := 100.0
export var time := 2.0

export var move_speed := 100.0
export var force_multiplier := 20.0

func _process(_delta):
    move()
    if $progress_sprite.scale == Vector2.ONE:
        shoot(Vector2.ONE)
    look_at(get_global_mouse_position())


func _on_tween_tween_step(_object, _key, _elapsed, value):
    shoot(value)

func shoot(scale_value: Vector2) -> void:
    if Input.is_action_just_pressed('space'):
        var bullet: Area2D = load("res://objects/bullet.tscn").instance()
        bullet.scale = scale_value
        bullet.position = position
    bullet.rotation_degrees = rotation_degrees + 180
    get_parent().add_child(bullet)

    apply_central_impulse(Vector2(100, 0))

    load_gun()


func load_gun() -> void:
    $tween.stop_all()
    $tween.interpolate_property($progress_sprite, 'scale', Vector2.ONE / 100 * min_value, Vector2.ONE / 100 * max_value, time, Tween.TRANS_LINEAR)
    $tween.start()


func move() -> void:
    var horizontal := Input.get_action_strength("d") - Input.get_action_strength("a")
    var vertical := Input.get_action_strength("s") - Input.get_action_strength("w")

    var vector := Vector2(horizontal, vertical)

    if vector != Vector2.ZERO:
        position += vector.normalized() * move_speed * get_process_delta_time()

player scene: https://1drv.ms/u/s!AomdJlENfLFloFNxRk3Vjd0V56px?e=FCNdbk

Godot version 3.3.2.stable.official
in Engine by (141 points)

Can you give us more information like what happens once you press "space"? Does bullet spawn? Do you have collision check implemented on bullet and player? Is it possible that bullets are colliding with player?

thanks to add_child the bullet is added to the scene, but because the player is rigidbody2d and the bullet is area2d they cannot collide.

it's because of the look_at function for some reason. How could it affect this?

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 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 webmaster@godotengine.org with your username.