Jump to content

Setting the position of a physics object


Rick
 Share

Recommended Posts

Is there any way to basically set the position of a physics object continuously and still have it's physics work? We all know using SetPosition() on a body stops physics from working. So how can I simulate a set position on a body?

 

I want to be able to set the position of a cube I have a physics body attached to and still have that physics body react to physics (ie, if a character jumps on it, the character won't fall through it. I don't have a mass on this physics body so it's like a floating cube in the world that I want to alter it's position yet still have the character controller able to stand on it)

Link to comment
Share on other sites

1. Use the calcomega and calcvelocity commands to calculate two vectors. Multiply these by the object mass, then add them as torque and force.

 

2. Use a static body you move around, and connect the dynamic body to it with a fixed joint.

 

You can probably come up with a function using technique 1 that is like SetPosition or SetRotation, but with physics forces.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

These cubes will always have a mass of 0 and will never twist or turn, just move forward/backward/left/right/up/down. So I assume I only need to mess around with the force value then if applied directly to the center of the physics body as I assume that shouldn't cause any sort of twisting of the object? I should have probably listened in physics class.

Link to comment
Share on other sites

Damn. So I assume I have to give it a mass and apply equal force on all sides to make it float? Then I guess I adjust the force on a given side to move it a certain direction?

 

Essentially I want to be able to move this cube to pivots that I place.

Link to comment
Share on other sites

The tests I made with storing the velocity and omega of an body,

then position it and restore both again, were promising.

Perhaps worth a try.

Core2DuoE6570 / Windows7 64bit / 4 Gb RAM / Geforce GTX 260 896Mb / LE 2.3

Dell Inspiron 1720 / Vista SP2 / C2D 2.4 / 8600 GM

Link to comment
Share on other sites

What do the platforms do? Are they just for your character to stand on? If so you could use a mass 0 one and SetPosition(). You might need to add a raycast from your character downwards and see if he's on a platform. If so, then adjust his height manually.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

I think I'll give your number 2 a shot. Seems easier.

 

"Use a static body you move around, and connect the dynamic body to it with a fixed joint."

 

I never played around with physics joints. Is the Vec3 in CreateJointFixed() a relative position from the parent or is it a global position? Also, if I make the parent body the one I move around, I assume the joint moves with it?

 

So in my moving platform I would make a body that I move with SetPosition(), and another body positioned above my first body. Then create a joint where the first body is the parent and the second body is the child?

Link to comment
Share on other sites

I got this working btw, and it's freaking sweet. I made some supporting Thingoids to make it able to be more dynamic.

 

I have a Cube Thingoid that has a physics body and you can apply a material to and resize.

I have a Body Thingoid that does basically the same thing but is just a body.

I have a Fixed Joint Thingoid that you assign 2 targets to. Target 0 is parent, target 1 is child.

I have a Pivot Thingoid that creates a pivot at the location of the object in the editor.

I have a MoveTo Thingoid. Target 0 is the body to call MoveEntity() on, and all the other targets will be the Pivot thingoid so it moves

between pivots.

 

 

It's really cool being able to just move the pivots around and see the cube move in any direction I make it, real-time!!! I'm excited.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...