#pick up / push mechanics for 3d character body
42 messages · Page 1 of 1 (latest)
I got push mechanics working (but a little janky) using an Area3D that's this wide circle around the bean and this script which finds all the bodies the Area is colliding with, then checks if it is a RigidBody3D, then applies a force in the direction between the player and the body. I have an export called PUSH_FORCE that controls how strong of a force to apply (I have it set to 0.2)
func _push_objects():
var bodies = $Pusher.get_overlapping_bodies()
for body in $Pusher.get_overlapping_bodies():
if body is RigidBody3D:
var force: Vector3 = -PUSH_FORCE * (position - body.position).normalized() * min(1.0, velocity.length())
body.apply_force(force)
I don't know about grabbing but I could try to put something together
bump
@urban jasper i have somehow found this and it pushes it but its very very glitchy but it does move it
I tried that, but I found my code to work better 🤷
whats the apply_force?
Did it though?
Try replacing line 82 with c.apply_force(force). The force is being applied to the thing you're trying to push, not to the character (which $"." is referencing)
it doesnt crash but it doesnt push it
still nothing
Can you send the complete code?
it either wants the players position or the boxes
c crashes and c.get_collider() doesnt
Oh I see, so basically for my project I had an Area3D called "Pusher" with a hitbox that extended around the player and so the bodies that got the force applied to them were the ones colliding with the Pusher Area3D
i know im trying to do it without using the area3d
thats why im using
so if i collide into a rigidbody3d
I could only get it to work using the area3d.
what would body be?
body is one of the nodes the Area3D is colliding with
You can get rid of the bodies variable declaration, I accidentally left it in there
i have it very slightly working but no clue what i did
@urban jasper i have some how made it chuck itself
ahhh its checking for a slide count right?
so it will only push it if i move side to side
so close
i cant get that to work
Why doesn't it work?
The collisionshape has a warning, can you tell me what it is please?
to be honest ive just gave up doing it way because i would say it isnt the best way to do it and i cant seem to get to correct