#Assistance with Physics - moving Rigidbody3d to a position

25 messages · Page 1 of 1 (latest)

rough zephyr
#

Hello.

I have a raycast. When I press a button, it should ideally do two things
Move a rigidbody to near a CharacterBody3d
Keep the rigidbody in the same relative position around that character body

Best example is gameplay from Control. Pick up an object it zooms to the character - it stays hovering around the character until it is thrown

I can detect what object is being selected, but moving the Rigidbody near the Characterbody is really hard/awkward. The best I can do is an impulse that ends up making the block hit the player. Attached is my code and a small vid.

Any advice to get closer towards the solution would be a big help 😭

edit: Found how to properly get the diff between 2 vectors (documentation came in clutch) but it still does not work right 🥹

rough zephyr
lethal wave
#

I would use some kind of physics joint, but if you want to directly set the position you can do so in the _integrate_forces() function

rough zephyr
lethal wave
#

Yeah, that's why I recommended using a joint

rough zephyr
# lethal wave Yeah, that's why I recommended using a joint

I tried using joints but I think I am misunderstanding something 😅

Setting the joint programmatically was pretty nice
but it seems like I can't make an offset as to where the joint will be placed near the player. So when I attach the block node programmatically it just defaults to the floor. I even messed with gravity and it still did that 😦
tried moving the joint super high, on the player (img 1) and below and regardless it seems the 2nd attached node's y wants to stay at the floor 😦

grave ginkgo
rough zephyr
grave ginkgo
rough zephyr
rough zephyr
grave ginkgo
#

If the attached box still doesn't move at all it's a good idea to check in the Remote view while it's running if the path to the second node was set correctly

rough zephyr
#

That's my bad I should have given a summary / quick explanation to the current problem 😭

The idea was to 'select' a box (Rigidbody) and move it to the top left of the character.
Frosty recommended a Joint, and I can see why. Its whole purpose is essentially stapling 2 nodes together.
However, I was struggling in finding how to adjust where the box was Joined with the player.

From my current code /video - it seems that when the box gets joined by the Player, it stays directly infront of the player model. Despite me moving the Joint in the editor 😦

tl;dr
Joint always staples the box infront of the player, I wanted it to go to the top left of the player

grave ginkgo
#

Ok, got it. So it does move with the player already just it's relative position isn't where you like it to be right?

When you connect a body with a joint it will use the current bodies offset to the joint as the "zero position".
For example, if you move the lower linear limit of the y axis up after the final connection the body should start to hover

rough zephyr
#

Yep spot on with the summary. It moves, its relative position isn't where I want it to be 😦

And lemme see if I understood that since im new to godot / gamedev 😅 when you say offset do you mean the diff between the joint & the 1st body?

and to make the body hover in my case, I should change the Linear Limit -> Y -> Lower distance after setting the new body on the joint?

grave ginkgo
# rough zephyr Yep spot on with the summary. It moves, its relative position isn't where I want...

To put a differently: when you connect the second body to the joint, where the joint or the first body is has no impact. The second body will stay exactly where it was. Now if you start rotating ( removing angular limits ) it will rotate around the joint, if you change linear limits those will be relative to the offset between joint and second body when it was connected.
So increasing the linear limit of the y-axis to let's say 1.0 will not put the body 1 meter above the joint but 1 meter above where the body was when you connected it to the joint.

#

That sentence got way more complicated than I intended 😄

#

Btw tough break working with 3d joints as a beginner. These things are notoriously difficult

rough zephyr
#

I seeeeeeeeeeeeeeeeeeeee

Joints are all about rotation.
So when I add the 2nd body to the joint that becomes the "offset". So any changes to the linear limit are from that position. So if I made a +1.0 lower linear limit on y, it'd be from the position when the 2nd body was added.

That is kinda odd 😦

So for my idea, of selecting a 3d body and having it consistantly be at the top left of my character, I'd have to do some of the following huh

  • translate (apply force to ) the rigidbody to whatever relative position on my character
  • increase the lower limits to whatever offset
  • use linear spring / linear motor to keep the body "spinning" in place so gravity won't bring it down
#

Yeah these things are the opposite of beginner friendly omfg LOL

part of me wonders if there's an easier implementation to what I wanna accomplish
(That being select a rigidbody 3d, move it to the player, and keep it at a constant distance) as opposed to this 😅

But your breakdown on Joints and offsets helped my understanding a bit! ❤️

grave ginkgo
# rough zephyr Yeah these things are the opposite of beginner friendly omfg LOL part of me wo...

For keeping a constant, fixed distance joints are the best option but as you can see a pretty complex one.

The simplest solution, which will be a bit more sluggish is to just place a Node on your player where the desired object position should be and the apply impulses or set linear velocity directly to there.

Something like
body.linear_velocity= ( target_node.global_position - body.global_position ) / delta
Might just work well enough

rough zephyr
#

Gotcha.

I'm going to fiddle around more with Joints because they seem pretty powerful when you get them 🤔 shame the documentation + learning curve on these guys seems kinda cruel 😭

the invis node idea also isn't a bad one. I'm doing a "pretend" game jam to see how much I can get done in a week so it isnt a big deal to spend some more time learning this stuff out

#

Thank you Codimon

for taking the time to listen, help explain, discuss, and provide some solutions on this dumb idea to a silly gamer
you rock dude ❤️

grave ginkgo