FPS Character holding a Rigidbody HL2 style?
Asked Answered
D

11

0

I'm trying to get a FP 3D character to "hold" rigidbodies and be able to move them around. The best way I've seen to do this is with a joint, but I don't know how to see which rigidbody is colliding with the holding "anchor" I've made. Does anyone have any ideas?

I don't know how to keep track of which specific rigidbody is colliding with the grab area

Deduce answered 21/3, 2023 at 3:7 Comment(0)
D
0

Deduce

After a few more revisions and -- I'VE GOT IT WORKING! Oh man, I feel so accomplished!! Thank you all for your help.
Here's my working code:

	if Input.is_action_pressed("use"):
		if holding_item == false:
			holding_item = true
			var picked_object = $head/Camera3D/use.get_collider()
			if picked_object != null:
				picked_object = $head/Camera3D/use.get_collider().get_path()
				$head/Camera3D/use/grab.set_node_b(picked_object)
	else:
		holding_item = false
		var picked_object = 0
		$head/Camera3D/use/grab.set_node_b("")

Deduce answered 21/3, 2023 at 6:47 Comment(0)
C
0

You should probably do this with a separate bunch of colliders on each limb connecting with the rigidbody? Detect when the limb is being clicked on and have the rigidbody follow that is what I'd do but haven't thought too much on the details of that problem yet. I myself have been exploring bullet spread options and AI.

Chequer answered 21/3, 2023 at 3:27 Comment(0)
D
0

Chequer My character doesn't have any limbs or even a real model right now, would things be any different?

(the object in front is the use_pos tree)

Deduce answered 21/3, 2023 at 3:32 Comment(0)
C
0

OH! Lol I thought when you meant half life 2 style you had a ragdoll setup my bad, I misunderstood, in this case if it's just a lone rigidbody or something you can either set the parent through the code to be a child of a node attached to your camera or you can have the position of the node follow the camera using global_transform.origin Done this myself for picking up crates with some admittedly mixed results, there are ways I'm looking at smoothing it in Godot.

Chequer answered 21/3, 2023 at 3:38 Comment(0)
D
0

Doughy answered 21/3, 2023 at 4:3 Comment(0)
D
0

Read this thread: https://mcmap.net/q/2022/godot-holding-a-rigidbody-object

Doughy answered 21/3, 2023 at 4:5 Comment(0)
C
0

I actually love playing with physics in an FPS, going to have to poke at that myself.

Chequer answered 21/3, 2023 at 4:16 Comment(0)
D
0

Doughy I looked through that thread earlier, I can't get the get_collider() function to work. Maybe a difference between Godot 3 and 4?

Edit: Wait a minute, I'm reading through it again, and the OP mentions a raycast, I thought it was just a Marker3D from the icon... I'll try using a raycast instead.

Deduce answered 21/3, 2023 at 4:19 Comment(0)
D
0

Deduce Alright, I've gone through and changed some things, and now I don't get any null errors, but I still can't grab anything.
(use and grab are under my head and camera so that the raycast and stuff follows where you look)

(edit: further code revision and better explanation)

Deduce answered 21/3, 2023 at 4:37 Comment(0)
D
0

Deduce

After a few more revisions and -- I'VE GOT IT WORKING! Oh man, I feel so accomplished!! Thank you all for your help.
Here's my working code:

	if Input.is_action_pressed("use"):
		if holding_item == false:
			holding_item = true
			var picked_object = $head/Camera3D/use.get_collider()
			if picked_object != null:
				picked_object = $head/Camera3D/use.get_collider().get_path()
				$head/Camera3D/use/grab.set_node_b(picked_object)
	else:
		holding_item = false
		var picked_object = 0
		$head/Camera3D/use/grab.set_node_b("")

Deduce answered 21/3, 2023 at 6:47 Comment(0)
D
0

Oh wow! That looks nice. I had to use a lot more code in Godot 3, I guess they improved it. Also, if you want to post code on the forum, type 3 tildes on a line by themself ~~~ directly above and directly below the code. Please avoid using screenshots of code. Thanks.

Doughy answered 21/3, 2023 at 8:32 Comment(0)
D
0

Doughy I redid that, thanks. I'll make sure to post the actual code instead of screenshots in the future.

Deduce answered 21/3, 2023 at 21:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.