Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Timofey |
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
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?
decepticlown | 2021-09-26 17:25
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.
Timofey | 2021-09-27 07:54
it’s because of the look_at function for some reason. How could it affect this?
Timofey | 2021-09-27 08:14