Hi all… I’m spankin’ new at all this… Unity as well as JS, so I sure could use a little hand holding from a kind soul. (I know Second Life and lsl, so I’m not clueless… just out of my element
I think what I need to do is simple, but I don’t know how to tie the pieces together.
I need to apply a force on an object relative to its direction vector. Let’s say the force is ALWAYS (0,-1,0) referenced to its direction of travel. It’s very much like drag!!! I need to use AddForceAtPosition to apply the force as I will have a need to specify exactly where the force is applied.
Lets say this position is at (0,1,0) in LOCAL space.
So here I am confused… I have a reference to direction, position in local space, and functions that (I think) only know world space.
Sounds like I have some converting I have to do… but honestly, I am lost at where to start.
I’d be forever grateful if someone could offer up systactically correct code that I could cut n paste that demonstrates the management of this problem…
(I hate asking for a code snippit, but as JS is new for me as well… I’d have a major case of FAIL just due to syntax)
No Far more complex than that, though it will do that if things are “right”.
Here is an example… if I were, in real life, to make an arrow, and stupidly put the feathers by the arrow head and shot it, it would not be pointing the way it was traveling for long. Aerodynamic forces would actually spin the arrow around and cause it to point exactly backward from it’s direction of flight.
What I want do do is apply forces to a rigidbody regardless of its orientation… like drag does, but that requires that I know its direction vector. Also, I need to apply this force to a specific local location… using the aformentioned function, which I believe uses world space.
So the task is complex, but the code should be simple.
Let me offer a sketch of what I think needs to happen to the rigid body.
1 - determine the vector that represents direction of travel.
2 - create a new vector that is in the opposite direction of vector 1, to a predetermied location on the rigid body (another topic, but basically a place that I determine represents the objects “center of pressure”). The degree of force is also a separate topic we need not concern ourselves with at the moment.
3 - convert this new vector to world space
4 - apply this vector to the rigid body with AddForceAtPosition
Hopefully my approach is sound, and the code is not too daunting (should be about 4 lines, yes?)
Not quite. A force that constantly changes depending on the direction of travel of the rigid body… acting in precisely the opposite direction of the direction of travel.
This then needs to be applied back to the object to a pre-determined point (I’ll take care of that), which I am given to understand must be done with a function requiring a world frame of reference… so it would need to be converted first.
OH! I see. And you want the specified point to be in local space, right? Oh, and do you want the force to be exactly equal to the speed of the rigidbody, or a specified force amount, just in the opposite direction?
Cp is the point I need to push… I will figure out how to come up with it…
But the issue is to create the proper vector to push at that point, and that comes from the air hitting the vehicle (which really has nothing to do with where it is pointed, except when things are aerodynamically stable)
I changed variables for the center of pressure and the center of mass for the object, and it became unstable when the Cp was forward of the Cg… and conversely became stable when the Cp was kept behind the center of mass.
And your questions were necessary… because I really had a hard time explaining it
I think that this is a really big deal… one line of code added a fundimental aerodynamic component to Unity not present in its physics engine.
I need a float that describes the magnitude (minus the direction) of the rigidbody speed. Not sure how to do that. Can one simply add the vector components? Multiply them?
Well, this is a separate issue… but yes, I am calculating a quantity as opposed to a fixed .25. That was just for testing. But as you can imagine, pressure increases with speed.
So from the velocity (direction + magnatude), I really need to simply get the magnatude, and I’m not sure if there is a function to do that.