3D Player Movement with GDScript: Simple Example & Code
extends KinematicBody\n\nvar speed = 10\nvar jumpForce = 10\nvar gravity = 20\nvar velocity = Vector3.ZERO\nvar isJumping = false\n\nfunc _physics_process(delta):\n\tvar moveDirection = Vector3.ZERO\n\tmoveDirection.x = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")\n\tmoveDirection.z = Input.get_action_strength("move_forward") - Input.get_action_strength("move_back")\n\tmoveDirection = moveDirection.normalized()\n\n\tvelocity.y -= gravity * delta\n\n\tif is_on_floor() and Input.is_action_just_pressed("jump"):\n\t velocity.y = jumpForce\n\t isJumping = true\n\n\tvelocity = move_and_slide(velocity, Vector3.UP)\n\n\tif isJumping and is_on_floor():\n\t isJumping = false\n\n\tif moveDirection != Vector3.ZERO:\n\t $Model.look_at($Model.translation + moveDirection, Vector3.UP)\n\n\tvelocity.x = moveDirection.x * speed\n\tvelocity.z = moveDirection.z * speed
原文地址: http://www.cveoy.top/t/topic/psIS 著作权归作者所有。请勿转载和采集!