Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Daraxus |
I am making a 2d arcade style shooter game and i’m trying to make the player shoot, but from the other code i’ve found and video nothing works. This is my current code.
extends KinematicBody2D
export var player_speed = 150
export var player_acceleration = 30
export var rotation_speed = 10
export (int) var max_health = 500
export (int) var current_health = 500
export (PackedScene) var bullet_scene
export (NodePath) var bullet_path_a
export (NodePath) var bullet_path_b
onready var bullet_scene = preload(“res://Scenes/bullet.xml”)
var bullet_speed = 400
var shooting = false
var killed = false
var velocity = Vector2()
func _ready():
set_fixed_process(true)
set_process_input(true)
set_process(true)
func _fixed_process(delta):
if Input.is_action_pressed(“btn_A”):
set_rot(get_rot() + delta * rotation_speed)
if Input.is_action_pressed(“btn_D”):
set_rot(get_rot() + delta * -rotation_speed)
if Input.is_action_pressed(“btn_W”):
move(Vector2((player_speed * sin(get_rot())) * delta, (player_speed * cos(get_rot())) * delta))
if Input.is_action_press(“btn_spacebar”):
shooting = true
var motion = velocity * delta
move(motion)
func shooting():
var bullet = bullet_scene.instance()
get_parent().add_child(bullet)
bullet.set_global_pos(get_node(“first_weapon”).get_global_pos())
bullet.set_linear_velocity(Vector2(sin(get_rot()) * bullet_speed, cos(get_rot()) * bullet_speed))
pass
Can someone help me with this.
Which version of Godot are you using? The script you provided is for Godot 2.X, but the current version is 3.2 where a lot of the methods you’re using are not working anymore. Take a look at this tutorial for an up-to-date script.
njamster | 2020-05-04 11:04
just from a quick look, the shooting function isn’t even being called…
try replacing the shooting = true
line in the process()
function with shooting()
zen3001 | 2020-05-04 16:18