apply_central_impulse not work rididbody2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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):
    if $progress_sprite.scale == Vector2.ONE:

func _on_tween_tween_step(_object, _key, _elapsed, 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
	apply_central_impulse(Vector2(100, 0))

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

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:!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