Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | potatobanana |
how to add and/or change bullet position and direction when lvl up?, this script somehow work, but i dont think this the right way to do it, can someone tell how to to it right or know any video for this ?
bullet scene
extends KinematicBody2D
export (int) var bullet_speed
export (int) var damage
export (float) var life_timer
var direction : Vector2 = Vector2.ZERO
func _physics_process(delta: float) -> void:
position += direction * delta
if global_position.y > 1290 or global_position.y < -10 or global_position.x > 730 or global_position.x < -10:
queue_free()
func bullet_spawn_position(bullet_pos, bullet_dir):
position = bullet_pos
rotation = bullet_dir.angle()
direction = bullet_dir* bullet_speed
player
extends "res://global_use/entity.gd"
var level = 1
func _ready() -> void:
global_position = get_viewport().size/2
func _process(delta: float) -> void:
control(delta)
func _input(event: InputEvent) -> void:
global_position = lerp((get_viewport().get_mouse_position()),global_position,0.6)
func control(delta):
if Input.is_action_pressed("Lclick"):
shoot()
if Input.is_action_just_pressed("ui_up"):
if level == 1:
level = 2
else:
level = 1
func shoot():
var bullet_dir = Vector2(1,0).rotated($gun.global_rotation)
var bullet_pos = $gun/bullet_spawn_pos.global_position
var bullet_dir2 = Vector2(1,0).rotated($gun2.global_rotation)
var bullet_pos2 = $gun2/bullet_spawn_pos.global_position
match level:
1:
emit_signal("shoot",bullet,bullet_pos,bullet_dir)
2:
emit_signal("shoot",bullet,bullet_pos2,bullet_dir2)
emit_signal("shoot",bullet,bullet_pos,bullet_dir)
world
extends Node2D
func _on_player_shoot(bullet,bullet_pos,bullet_dir) -> void:
var bullet_instance = bullet.instance()
bullet_instance.bullet_spawn_position(bullet_pos,bullet_dir)
add_child(bullet_instance)
this script somehow work, but i dont think this the right way to do it
Why do you think that? I don’t see anything wrong with your approach.
njamster | 2020-03-03 12:25
because i cant send less than 5 argument when i need just 3 for lvl 1 ~ 2. but i need 5 argument when lvl 3.
and some tutorial tip say, use less signal if can.
player
i dont need argument in red box. still need to put something or i will get error. what should i do?
world
lvl 1 i need 1 bullet, i emit 5 argument but use only 3
lvl 2 i need 3 bullet, i emit 5 argumentx2 but use only6
lvl 3 i need 9 bullet, use all
i also try something like this but i dont know which one will make me easy to modified later on.
world
func _on_player_shoot(bullet,bullet_pos,bullet_pos2,bullet_pos3,bullet_dir,bullet_dir2,bullet_dir3,bullet_dir4,bullet_dir5,bullet_dir6,bullet_dir7,bullet_dir8,bullet_dir9) -> void:
var bullet_instance = bullet.instance()
var bullet_instance2 = bullet.instance()
var bullet_instance3 = bullet.instance()
var bullet_instance4 = bullet.instance()
var bullet_instance5 = bullet.instance()
var bullet_instance6 = bullet.instance()
var bullet_instance7 = bullet.instance()
var bullet_instance8 = bullet.instance()
var bullet_instance9 = bullet.instance()
bullet_instance.bullet_spawn_position(bullet_pos,bullet_dir)
bullet_instance2.bullet_spawn_position(bullet_pos2,bullet_dir2)
bullet_instance3.bullet_spawn_position(bullet_pos3,bullet_dir3)
bullet_instance4.bullet_spawn_position(bullet_pos,bullet_dir4)
bullet_instance5.bullet_spawn_position(bullet_pos,bullet_dir5)
bullet_instance6.bullet_spawn_position(bullet_pos2,bullet_dir6)
bullet_instance7.bullet_spawn_position(bullet_pos2,bullet_dir7)
bullet_instance8.bullet_spawn_position(bullet_pos3,bullet_dir8)
bullet_instance9.bullet_spawn_position(bullet_pos3,bullet_dir9)
match global_data.level:
1:
add_child(bullet_instance)
2:
add_child(bullet_instance)
add_child(bullet_instance2)
add_child(bullet_instance3)
3:
add_child(bullet_instance)
add_child(bullet_instance2)
add_child(bullet_instance3)
add_child(bullet_instance4)
add_child(bullet_instance5)
add_child(bullet_instance6)
add_child(bullet_instance7)
add_child(bullet_instance8)
add_child(bullet_instance9)
player
extends "res://global_use/entity.gd"
var level = 1
func _ready() -> void:
global_position = get_viewport().size/2
func _process(delta: float) -> void:
control(delta)
func _input(event: InputEvent) -> void:
global_position = lerp((get_viewport().get_mouse_position()),global_position,0.6)
func control(delta):
if Input.is_action_just_pressed("Lclick"):
shoot()
if Input.is_action_just_pressed("ui_up"):
if global_data.level < 3:
global_data.level +=1
else:
global_data.level = 1
if global_data.level == 1 :
$gun2.visible = false
$gun3.visible = false
elif global_data.level == 2 and 3:
$gun2.visible = true
$gun3.visible = true
print(global_data.level)
func shoot():
var bullet_pos = $gun/bullet_spawn_pos.global_position
var bullet_pos2 = $gun2/bullet_spawn_pos.global_position
var bullet_pos3 = $gun3/bullet_spawn_pos.global_position
var bullet_dir = Vector2(1,0).rotated($gun.global_rotation)
var bullet_dir2 = Vector2(1,0).rotated($gun2.global_rotation)
var bullet_dir3 = Vector2(1,0).rotated($gun3.global_rotation)
var bullet_dir4 = Vector2(1,0).rotated($gun.global_rotation + 0.2)
var bullet_dir5 = Vector2(1,0).rotated($gun.global_rotation - 0.2)
var bullet_dir6 = Vector2(1,0).rotated($gun2.global_rotation + 0.2)
var bullet_dir7 = Vector2(1,0).rotated($gun2.global_rotation - 0.2)
var bullet_dir8 = Vector2(1,0).rotated($gun3.global_rotation + 0.2)
var bullet_dir9 = Vector2(1,0).rotated($gun3.global_rotation - 0.2)
emit_signal("shoot",bullet,bullet_pos,bullet_pos2,bullet_pos3,bullet_dir,bullet_dir2,bullet_dir3,bullet_dir4,bullet_dir5,bullet_dir6,bullet_dir7,bullet_dir8,bullet_dir9)
thank for answer all my previous question too, may i know if you make any game for pc? you look like professional.
potatobanana | 2020-03-03 15:50