3D, 贴地运动

贴地运动,想要做好一款游戏,需要非常多的数学知识 

https://kidscancode.org/godot_recipes/4.x/3d/3d_align_surface/index.html

 

 


func align_with_y(xform, new_y):
  xform.basis.y = new_y
  xform.basis.x = -xform.basis.z.cross(new_y)
  xform.basis = xform.basis.orthonormalized()
  return xform

 

func _physics_process(delta):
  velocity += gravity * delta
  get_input(delta)
  velocity = move_and_slide_with_snap(velocity, Vector3.DOWN*2, Vector3.UP, true)
  var n = $RayCast.get_collision_normal()
  var xform = align_with_y(global_transform, n)
  global_transform = global_transform.interpolate_with(xform, 12 * delta)

posted @ 2024-07-09 17:32  porter_代码工作者  阅读(7)  评论(0编辑  收藏  举报