You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Godot 3.3.4 3D俯视游戏玩家斜坡站立滑动问题及解决方法

我在Godot 3.3.4中开发一款3D俯视视角游戏,编写的玩家移动代码存在玩家站在斜坡上时会缓慢滑动的问题。我大概能想到修复思路,但担心把简单问题复杂化,因此想请教社区有没有让玩家触地时固定在原地的简单方案?我知道move_and_slide_with_snap()方法,但我尝试后没能正常生效,同时我也清楚我原先的代码漏了delta参数的应用。

原先的代码如下:

export var speed = 7.5
const GRAVITY = Vector3.DOWN * 100

var velocity = Vector3.ZERO

func _physics_process(delta):
  velocity += GRAVITY * delta
  velocity = move_and_slide(velocity, Vector3.UP)
  
  var input_vector = Vector2.ZERO
  input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
  input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
  input_vector = input_vector.normalized()
  
  velocity.x = input_vector.x * speed
  velocity.z = input_vector.y * speed
  

  move_and_slide(velocity)

这是我第一次在社区提问,先提前感谢大家的帮助。

已解决

感谢Theraot的帮助,我开启了斜坡相关设置但仅偶尔生效,因此我调整了代码,目前效果符合预期,调整后的代码如下:

extends KinematicBody

export var speed = 750
const GRAVITY = Vector3.DOWN * 10

var velocity = Vector3.ZERO

func _physics_process(delta):
    velocity += GRAVITY * delta
    velocity = move_and_slide_with_snap(velocity, Vector3.DOWN, Vector3.UP, true, 1, 0.80)
    
    var input_vector = Vector2.ZERO
    input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
    input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
    input_vector = input_vector.normalized()
    
    velocity.x = input_vector.x * speed * delta
    velocity.z = input_vector.y * speed * delta
    

    move_and_slide_with_snap(velocity, Vector3.DOWN, Vector3.UP, true, 0, 0.785398)

我知道代码还有优化空间,目前移动效果正常,仅在大坡度斜坡上会有少量滑动,可以当作游戏特色处理。此问题就此关闭,若有朋友想优化代码也欢迎提出建议,祝大家开发顺利。


内容的提问来源于stack exchange,提问作者uberflut

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 23:36:03