Advertisement
Lakamfo

Interactive rigid body

Apr 28th, 2023
2,011
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.71 KB | Gaming | 0 0
  1. extends RigidBody
  2. class_name Interactive
  3.  
  4.  
  5. var target = null
  6. var velocity = Vector3()
  7.  
  8. func _physics_process(_delta):
  9.     if target:
  10.         self.linear_velocity = (target.global_transform.origin - global_transform.origin) * 5
  11.         #global_transform = global_transform.interpolate_with(target.global_transform, delta * 15)
  12.  
  13. func take(_target):
  14.     target = _target
  15.     mode = RigidBody.MODE_RIGID
  16.  
  17.  
  18. func drop():
  19.     target = null
  20.     mode = RigidBody.MODE_RIGID
  21.     var dir = transform.basis.z
  22.     apply_central_impulse(dir * -1)
  23.  
  24.  
  25. func push():
  26.     target = null
  27.     mode = RigidBody.MODE_RIGID
  28.     var dir = GlobalGd.player.head.global_transform.basis.z
  29.     dir = dir.rotated(Vector3.UP, 0.1)
  30.     dir.y -= 0.2
  31.     apply_central_impulse(dir * -10)
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement