#pick up / push mechanics for 3d character body

42 messages · Page 1 of 1 (latest)

brave geode
#

i want to make it so my 3d character body can pick up / push rigid bodys like whats in the game "portal"

urban jasper
#

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

brave geode
#

bump

brave geode
#

@urban jasper i have somehow found this and it pushes it but its very very glitchy but it does move it

urban jasper
#

I tried that, but I found my code to work better 🤷

brave geode
#

idk

#

im guessing that wont work

urban jasper
brave geode
#

no

urban jasper
#

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)

brave geode
#

it doesnt crash but it doesnt push it

urban jasper
#

Why are you using $"."?

#

Try replacing it with c

brave geode
urban jasper
#

Can you send the complete code?

brave geode
brave geode
urban jasper
#

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

brave geode
urban jasper
#

This is my player nodetree

#

This circle around the player is the pusher's hitbox

brave geode
#

i know im trying to do it without using the area3d

#

thats why im using

#

so if i collide into a rigidbody3d

urban jasper
urban jasper
#

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

brave geode
#

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

urban jasper
#

Why doesn't it work?

brave geode
#

does not push it

urban jasper
# brave geode

The collisionshape has a warning, can you tell me what it is please?

brave geode
#

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