godot游戏引擎吧 关注:59贴子:119
  • 0回复贴,共1

GD按键控制角色移动旋转算法

只看楼主收藏回复

extends Sprite
#Godot游戏引擎 讨论QQ群 302924317
func _ready():
set_fixed_process(true)var SPEED = 50func _fixed_process(delta):
if Input.is_key_pressed(KEY_W):
var current_rotation = get_rot()
translate(Vector2(sin(current_rotation), cos(current_rotation)) * -SPEED * delta)
if Input.is_key_pressed(KEY_S):
var current_rotation = get_rot()
translate(Vector2(sin(current_rotation), cos(current_rotation)) * SPEED * delta)
if Input.is_key_pressed(KEY_A):
var current_rotation = get_rot()
set_rot(current_rotation+5*delta)
if Input.is_key_pressed(KEY_D):
var current_rotation = get_rot()
set_rot(current_rotation-5*delta)
#Godot游戏引擎 讨论QQ群 302924317


IP属地:广西1楼2017-03-04 09:22回复