【发布时间】:2021-07-11 01:53:46
【问题描述】:
为什么当我将它运行到我的应用程序时已关闭并编写它 - 基础 Node2D 中不存在函数 apply_impulse。我看到 Godot 的文档,我找到了它的方法,你的父母是 RigidBidy2D,但我通过视频做这段代码,他使用 KinematicBody2D,没关系
extends KinematicBody2D
var movespeed = 500
var bulletspeed = 2000
var bullet = preload("res://Bullet.tscn")
func _ready():
pass
func _physics_process(delta):
var motion = Vector2()
if Input.is_action_pressed('up'):
motion.y -= 1
if Input.is_action_pressed('down'):
motion.y += 1
if Input.is_action_pressed('right'):
motion.x += 1
if Input.is_action_pressed('left'):
motion.x -= 1
motion = motion.normalized()
motion = move_and_slide(motion * movespeed)
look_at(get_global_mouse_position())
if Input.is_action_just_pressed('LMB'):
fire()
func fire():
var bullet_instance = bullet.instance()
bullet_instance.position = get_global_position()
bullet_instance.rotation_degrees = rotation_degrees
bullet_instance.apply_impulse(Vector2(), Vector2(bulletspeed, 0).rotated(rotation))
get_tree().get_root().call_deferred("add_child", bullet_instance)
【问题讨论】:
-
能否请您显示一下错误堆栈?
标签: documentation game-development godot gdscript