2021-08-21 Godot Engine 견과&우유 사다리 등 실시
15256 단어 Godot
Windows 10 Pro v21H1
Godot Engine v3.3.2.stable.official
참고 자료유저에 첨부된 스크립트
Player.gd
extends KinematicBody2D
export (int) var run_speed = 200
export (int) var gravity = 1000
export (int) var jump_speed = -400
var velocity = Vector2()
var jumping = false
var area_entered = false # はしご接触中
onready var area = get_node("../Area2D") # はしご
func _ready():
pass # Replace with function body.
func get_input():
velocity.x = 0
var right = Input.is_action_pressed("ui_right")
var left = Input.is_action_pressed("ui_left")
var jump = Input.is_action_just_pressed("ui_accept")
# はしごに接触しているか検知
var isOverlap = false
for body in area.get_overlapping_bodies(): # Area2DにPlayerが入ったことを検知
isOverlap = true
if isOverlap:
area_entered = true
else:
area_entered = false
# その他の処理
if jump and is_on_floor():
jumping = true
velocity.y = jump_speed
if right:
velocity.x += run_speed
if left:
velocity.x -= run_speed
func _physics_process(delta):
get_input()
if area_entered: # はしご接触中
velocity.y = 0.0
else:
velocity.y += gravity * delta
if jumping and is_on_floor():
jumping = false
velocity = move_and_slide(velocity, Vector2(0, -1))
실행 결과점프 후 사다리에 오르는 상태
시험을 준비하다
견과류와 우유도 사다리를 오르내리며 움직였지만 이번에는 실장하지 않았다.처리가 복잡하지 않다.
사다리를 오르내리다
상하 이동이 이루어졌다.잘 설치되지 않았습니다.
Player.gd
extends KinematicBody2D
export (int) var run_speed = 200
export (int) var gravity = 1000
export (int) var jump_speed = -400
enum {
YDIR_FALL = 0,
YDIR_STOP,
YDIR_UP,
YDIR_DOWN,
}
var velocity = Vector2()
var jumping = false
var area_entered = false # はしご接触中
var ydir_type = YDIR_FALL
onready var area = get_node("../Area2D") # はしご
func _ready():
pass # Replace with function body.
func get_input():
velocity.x = 0
var right = Input.is_action_pressed("ui_right")
var left = Input.is_action_pressed("ui_left")
var up = Input.is_action_pressed("ui_up")
var down = Input.is_action_pressed("ui_down")
var jump = Input.is_action_just_pressed("ui_accept")
# はしごに接触しているか検知
var isOverlap = false
for body in area.get_overlapping_bodies(): # Area2DにPlayerが入ったことを検知
isOverlap = true
if isOverlap:
area_entered = true
else:
area_entered = false
# その他の処理
if jump and is_on_floor():
jumping = true
velocity.y = jump_speed
if right:
velocity.x += run_speed
if left:
velocity.x -= run_speed
if area_entered:
ydir_type = YDIR_STOP
if up:
ydir_type = YDIR_UP
if down:
ydir_type = YDIR_DOWN
else:
ydir_type = YDIR_FALL
func _physics_process(delta):
get_input()
if ydir_type == YDIR_STOP: # はしご接触中
velocity.y = 0.0
elif ydir_type == YDIR_UP:
velocity.y -= run_speed * delta
elif ydir_type == YDIR_DOWN:
velocity.y += run_speed * delta
else:
velocity.y += gravity * delta
if jumping and is_on_floor():
jumping = false
velocity = move_and_slide(velocity, Vector2(0, -1))
Reference
이 문제에 관하여(2021-08-21 Godot Engine 견과&우유 사다리 등 실시), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/7of9/items/49c17a8c9292c23e49e5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)