您当前的位置: 首页 >  3d

暂无认证

  • 8浏览

    0关注

    97548博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Godot Engine:3D角色移动(走/跑/跳)(重力问题已更正)

发布时间:2019-12-31 18:55:34 ,浏览量:8

实现了走/跑/跳,

在这里插入图片描述

extends KinematicBody

class_name Player

const walk_speed = 5.0 const run_speed = 10.0 var gravity:Vector3 = Vector3.DOWN*12 var speed:float = walk_speed
var jump_speed:float = 6.0 var velocity : Vector3 = Vector3.ZERO
var jump : bool = false


func _ready(): add_to_group("player") func _physics_process(delta): velocity += gravity*delta
	get_input() velocity = move_and_slide(velocity,Vector3.UP) if jump and is_on_floor(): velocity.y = jump_speed
	
func get_input(): var vy = velocity.y
	velocity = Vector3.ZERO if Input.is_action_pressed("ui_run"): speed = run_speed if Input.is_action_just_released("ui_run"): speed = walk_speed if Input.is_action_pressed("ui_up"): velocity += Vector3.FORWARD if Input.is_action_pressed("ui_down"): velocity += Vector3.BACK if Input.is_action_pressed("ui_left"): velocity += Vector3.LEFT if Input.is_action_pressed("ui_right"): velocity += Vector3.RIGHT
	
	
	velocity = velocity.normalized()*speed if velocity != Vector3.ZERO: look_at(translation - velocity,Vector3.UP) velocity.y = vy #动作键和跳跃键 if Input.is_action_just_pressed("ui_action"): print("action") jump = false if Input.is_action_just_pressed("ui_jump"): jump = true
关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

1.1100s