Carrying around physics objects

Hi,

I am trying to implement a player carrying around a physics object (a box in this case) like in Half Life 2, Portal or Penumbra series.
First, I tried to parent the box to the player. However, this prevented physics behavior of the carried object.
My second approach was to use a constraint which appends the carried object to the player. This approach has the problem that as soon as the forces on the object get too strong, the cube jets jiggly and moves through other objects (which is obviously due to the hard constraint).
The behavior is demonstrated in the video below:

https://youtu.be/W5YT4jlwGog

I tried to improve the behavior by setting the linear velocity of the object directly (instead of using a constraint) – with the same result.
Also applying a force to the cube did not yield the desired result, since it caused a delay in the movement of the cube relative to the player (depending on the intensity of the applied force).

Does anybody have an idea on how to create a more flexible constraint that allows moving the player towards a wall, causing the object getting closer to the player (like in the other games mentioned above)?

thanks and best regards,
Carsten

Maybe if you use the steering actuator to make the cube steer to an empty parented to the camera.

I have made many of those type of mechanics,

what you want to do, is store the localized position of the crate on pick up, and have the object apply forces to stay in the target area,

tutorial on the way and file,

you can also use a mouse property generator, to move the goal location…
(hold button to swing crate around like jedi)

edit:
video 1, getting a local position from a ray

For a game that I was developing I made one system like that. I tested three methods:
-Using a constraint on the grabbed object.
-Applying forces to the grabbed object.

And finally this method, that I think is the best way. You have to substract two position vectors: the place where you want the object to move (in this case it will be a empty parented to the camera) and the position of the object. Now you need to use this value as the global linear velocity of the grabbed object (instead of applying forces).

To avoid the object to rotate without control when dragging it against a wall or from jiggling, you reduce its angular and linear velocity.

This is part of my code:


#Reduce the velocity of the object
heldObject.localLinearVelocity *= 0.0
heldObject.localAngularVelocity *= 0.04
        
#Atract it
velocity = grabPosition.worldPosition - heldObject.worldPosition
heldObject.setLinearVelocity((velocity)*12)

Attachments

GrabITThree.blend (473 KB)

Thank you for your quick replies!

@BluePrintRandom: I watched your two videos, and tested your .blend-file. However, it doesn’t solve my problem (the jiggly behavior).
At the time of my original post, I was already able to pick up objects. The video in my first post shows the behavior of my code. I downloaded your file and added a wall and a floor. The following video shows the same jiggly behavior:

@carlo697: I tried reducing linear and angular velocity like you do in your code above (my code actually looks pretty similar to yours). The jiggling gets better by multiplying the angular velocity by a small value, but doesn’t actually disappear (even if I multiply by 0). Maybe the applied velocity (the factor, 12 in your case) should be less if the forces applied to the cube are very strong, but I don’t have a clue on how to detect that (I read that the forces can’t directly be read).

@Nicholas_A: I don’t really get your point. Do you suggest to move the cube by receiving keyboard input?

just for fun:

Monster’s manic gadgets - the attractor

I had a similar approach with carlo697 but with applyForce and set the force base on distance between hand and object, and then cap them to 0 so the simulation won’t explode


force = 100
offset_distance = target.worldPosition-obj.worldPosition
damping_force =  force*offset_distance.magnitude
obj.applyForce(offset_distance*damping_force,False)
obj.setLinearVelocity([0.0, 0.0, 0.0], False)
obj.setAngularVelocity([0.0, 0.0, 0.0], False)

It should* behave like most grab mechanics out there, however you may need verlet velocity or other damping method if the object still go through the wall

(deleted)
sorry for double posting (this was since you can’t see your post until it is accepted by a moderator)

I already tried applying forces instead of setting the linear velocity directly. Without resetting the linear force, the cube has a very bouncy behavior. With resetting, however, the behavior is similar to the solution where linear velocity is being set directly (still jiggly).
BTW, I am curious, why you (guramarx) reset the linear velocity after applying the force. Doesn’t this also reset the velocity caused by the applied force?

I guess the grabbing point (i.e. the player’s hand) has to be moved closer to the player, when standing in front of a wall in order to avoid jiggling. Is there any way to detect if the cube is being pushed against a wall?

I already tried applying forces instead of setting the linear velocity directly. Without resetting the linear force, the cube has a very bouncy behavior. With resetting, however, the behavior is similar to the solution where linear velocity is being set directly (still jiggly).
BTW, I am curious, why you (guramarx) reset the linear velocity after applying the force. Doesn’t this also reset the velocity caused by the applied force?

It will explode if the force is left “growing”, I don’t see any jiggle when the object is placed near a wall/floor?

I guess the grabbing point (i.e. the player’s hand) has to be moved closer to the player, when standing in front of a wall in order to avoid jiggling. Is there any way to detect if the cube is being pushed against a wall?

yes, rayCast can do that but the code I posted should push the object towards you and not into the wall, irregardless of where you hand is grabbing

I can do exactly what you ask,

compound parent the object to the actor core, mark the actor core compound physics bound,

example incomming.

I liked monsters file. i’m sure if u want physics still while u hold the object his file is best. Blueprintrandoms is the way i would go to make it easy. i’ve done it his way before it works fine.

@guramarx: I understand why you reset the velocity, but I am curious if there is a difference whether you do it before applying the force or doing it afterwards (i.e. when is the applied force converted into a velocity?).

@tuschcarsten
well, from my game they do behave differently, I can’t say for certain how the order matters, as the game engine process in the order of logic(brick and script) > physics > render so a vague idea is that there exist some sort of delay between what you see and what is going on… I don’t know :spin: