belfegor wrote:[...]
Sorry man, been a bit busy (haven't coded, too much crappy school-work).
What do are all the line variables for (EndLine, etc.)? From a look at your code, seems like you have a lot of unneeded things in there.
Here's a quick idea of what I'm doing:
Code: Select all
Ogre::Vector3 hop = heldObject->getPosition();
// make the held object go to us
Ogre::Vector3 vel = getHoldPosition() - hop;
// make the object go there faster
const float HOLD_STRENGTH = 18.75;
heldObject->setDesiredVelocity(vel * HOLD_STRENGTH);
It simply checks where the object is, and the velocity is the difference of the desired position from the object's position (how you determine the desired position is up to you - I see you have some code in there for it already).
setDesiredVelocity() simply sets a member variable called dvel to whatever you pass into the function (it also enables the "desired velocity" effect if disabled).
Then, in the force and torque callback (for the held object):
Code: Select all
void Object::cb_fat() {
[...]
float _tmass, _tix, _tiy, _tiz;
NewtonBodyGetMassMatrix(newtBody, &_tmass, &_tix, &_tiy, &_tiz);
float ts = NewtonGetTimeStep(PhysicsManager::singleton()->gWorld());
if (dvelEnabled) {
Ogre::Vector3 cvel = getVelocity();
addForce(_tmass * (dvel - cvel) / ts);
}
[...]
}
... and that's pretty much it. addForce does a standard NewtonBodyAddForce(), getVelocity() return's the object's velocity (NewtonBodyGetVelocity()), and gWorld() returns the global newton world.
(the result is something like this:
http://www.youtube.com/watch?v=YYGsJ88xsm4 - the video is a bit long, but the effect is seen in the first few seconds, so it shouldn't make a difference - note how it doesn't have that spring-effect - I used to have that, too, if you look at one of my older videos
)
Note: there's an annoying little side-effect. The force seems to be too strong and even at high mass ratios a massive object gets easily pushed by a not-so-massive object. I believe manual dampening of the force (not via the mass) fixes this.
BTW, while we're sharing ideas and code
, mind giving me a pointer (no pun intended
) as to how you've achieved jumping for the character? How do you check whether the character should be able to jump? I can't come up with a solid method for this. Also, how did you do the 0-bounce for the character? It's really neat! (If I set my character to 0-bounce, he'll usually end up half-way in the ground.)