Hi everyone!
I'm trying to make a small 3D first player game where you can grab a rigidbody, for that i use this code for detect the object:
func detect_object():
object_detector.force_raycast_update()
if grabbed_object == null:
object_detector.show()
if object_detector.get_collider() is RigidBody:
object_detect = true
else:
object_detect = false
else:
object_detector.hide()
(object_detector is a raycast on my camera)
For grab i use this code:
func grab():
if Input.is_action_just_pressed("Grab") and object_detect:
if grabbed_object == null:
grabbed_object = object_detector.get_collider()
grabbed_object.mode = RigidBody.MODE_STATIC
else:
grabbed_object.mode = RigidBody.MODE_RIGID
grabbed_object.apply_impulse(Vector3(0, 0, 0), -camera.global_transform.basis.z.normalized() * OBJECT_THROW_FORCE)
grabbed_object = null
if grabbed_object != null:
grabbed_object.global_transform.origin = grab_point.global_transform.origin
(grab_point is a spatial node on the front of the player)
-First problem:
When i look around with the rigidbody grabbed, this one turn on itself on the y axis, i try to lock this axis but I'm not able to found a solution...
(NB: later i would like the player can be able to rotate the rigidbody with a input)
-Second problem:
The collision of the rigidbody is disable when is grabbed and i dont want that..
Somebody can help me please?