Jump to content

AddBodyForce trying to get it to work...


Chiblue
 Share

Recommended Posts

I have a Mesh that I am trying to push sideways...

 

I have the object... and I create a cylinder, then parent it, assign a mass and then AddBodyForce, I want to move the object to the right when applying the force but I have tried just adding the force on the X axis, which works but when I rotate the object around the Y axis the object flies of in different directions, when in one direction is is fine, but them it goes forward left, obviously the function does not work how I expected it, or I am doing something else wrong.. Oh the object is set using PointEntity with the camera... so it is always pointing away from it.. (after a 180 rotation)

 

 

TBody objectBody = CreateBodyCylinder(0.1, 0.3);

EntityParent(object, objectBody );

SetBodyMass(objectBody ,0.1);

EntityType(objectBody ,2);

AddBodyForce(objectBody ,Vec3(10,0,0),0);

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

According to the wiki what you have should work, but it seems that it's applying the force using the global coordinate system instead of the local. You could try switching the third parameter to 1 or using TFormVector to create the vector you want in global space and use that.

 

Oh, one other thing that might be an issue, if you are pointing the object and not the body then the body and model might be out of sync. So the body is still moving to its right, but the model is now facing a different direction.

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

ZBrush - Blender

Link to comment
Share on other sites

If using physics you should exclusively use physics. Use physics to turn the cube instead of PointEntity. You can't really mix manual positioning and physics, they don't play well together.

 

Please explain how I rotate a body in physics without using RotateEntity?

 

I do not see any rotation commands in the bodies wiki?

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

Do I have to position and rotate the body to match the mesh before attaching it to the mesh?

 

TBody objectBody = CreateBodyCylinder(0.1, 0.3);

PostionEntity(objectBody,EntityPosition(object),1);

RotateEntity(objectBody,EntityRotation(object),1);

EntityParent(object, objectBody );

SetBodyMass(objectBody ,0.1);

EntityType(objectBody ,2);

AddBodyForce(objectBody ,Vec3(10,0,0),0);

 

Could this be the problem?

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

AddBodyForce(objectBody ,Vec3(10,0,0),0);

 

Remember, that's only going to make the body to its right, irrespective of the camera's angle

 

Changing the last '0' for a '1' will make it constantly make it move to the right in the world, irrespective of both the camera's angle, and the body's own orientation.

 

If you instead write:

 

TVec3 AddForce = Vec3(10,0,0);
AddForce = TFormVector(AddForce,camera,0);
AddBodyForce(objectBody ,AddForce,0);

 

That will add the force relative to the camera angle (if your camera is called 'camera'). The above three lines could be condensed into one, as follows:

 

AddBodyForce(objectBody ,TFormVector(Vec3(10,0,0),camera,0),0);

 

...And if the camera is constantly rotated to match the body's rotation, that gives a first person style view.

 

 

Without meaning to be nasty, if you've not watched the 'introduction to bodies' video tutorial, it's worth watching.

 

http://www.leadwerks.com/files/Tutorials/CPP/Introduction_To_Bodies.wmv

http://www.leadwerks.com/files/Tutorials/CPP/Making_A_Spectator.wmv

LE Version: 2.50 (Eventually)

Link to comment
Share on other sites

Remember, that's only going to make the body to its right, irrespective of the camera's angle

 

That is exactly what I wanted to happen... Also I have benn through the tutorials, all of them... but like most the tutorials are a guide, after that everything is a learning experience...

 

Without meaning to be nasty, if you've not watched the 'introduction to bodies' video tutorial, it's worth watching.

 

 

The only reason I post these questions is that I know most of my chaleenges have been resolved by you guys in one way of another so I am simply looking for guidance, I appologize if it's a frustration but I thought that was the point of the forums to learn and help others...

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

Try creating it in lua in the editor and turning on physics visualization so you can see what's going on.

 

Did that and found my problem, the problem was that the body was not surrounding the object... I positioned and rotated the body before making it a child and now I have a perfect representation of the force I wanted... Thanks again...

If it's not Tactical realism then you are just playing..

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...