Problem with character movement

Hansel

21-06-2006 16:21:37

Hello :D

This is Ash:



I am triying to move Ash character over the next scene:





And I have a problem: Ash bounces when I move it but just a little bit, just the little bit the camera (which is attached to Ash and always behind him in a constant relative position) needs to turn me crazy, because it bounces with my character.

I have created several materials: one for Ash, one for terrain, another one for ruins... and I have set all the materialpairs I need between ash material and the others. Then I put the friction to (0,0) and elasticity to 0, but Ash is still bouncing across the scene like the first time, but in this case without friction. I want to erase that damned vibration :evil: :lol:

I donĀ“t know how to fix this :cry: Anyone can help me? Thanks :D

abecam

21-06-2006 18:44:41

Maybe a UpVector-joint??? Or you can find a way to help te character to levitate (I achieved to have something working, but it had a huge inertie). Also you might try to have another collision shape, more landscape-friendly, like a sphere. I am interested also if a better solution exist.
Just some suggestions then, I am not an expert (I just enjoy ONewt a lot !!! Soon I will have a demo :) )

Hansel

21-06-2006 21:44:52

I use an UpVector join ;)

OgreNewt::BasicJoints::UpVector* uv = new OgreNewt::BasicJoints::UpVector(mWorld,ash->get_body(),Vector3::UNIT_Y);


And the collision shape is an ellipsoid (a sphere in this case). But Ash bounces every time I press W or S keys, even if Ash is fliying or even if there is no terrain below :?

OvermindDL1

22-06-2006 00:08:06

Try using the latest (recently released) Newton library. As I recall, it fixes some things related to things like that...

Hansel

22-06-2006 10:59:04

I installed the latest newton librarys and there is no changes :(


I add another question :mrgreen:

I want the camera to adjust to the terrain height in each zone in order to get it always over the terrain. As I said the camera goes all the time behind Ash. I think perhaps raycasting can be useful to me in order to calculate every new "relative to Ash" height but I don't have any idea about using raycasting. Anyones knows if it's possible to do?

In addition, I also think if I adjust the camera height by this way perhaps it fixes the vibration problem too.

abecam

22-06-2006 12:02:43

I did use the raycast :) (basic raycast then) To adapt the force I applied following the terrain. And once again, Walaber did an amazing job it is very very easy to use.


Here is my old code, with few changes to be clearer, hope it is not too old:




// Into the character force&Torque callback

OgreNewt::BasicRaycast myRay(me->getWorld(),rayStart,rayEnd); // rayStart and rayEnd: Vector3, position in global space (not relative)

if ( (myRay.getHitCount() == 0) || ( (myRay.getHitCount()==1) && (myRay.getFirstHit().mBody == me) ) )
{
// No collision... 1 hit and mBody=me mean that the ray just touched myself !!! (you can obviously avoid that when you choose the start point of the ray)
}
else
{
float distToFive;
if ( myRay.getFirstHit().mBody == me)
{
// The distance to the hit is: myRay.getInfoAt(1).mDistance;
// We first have an hit with ourself, but still we have another object below
//LogManager::getSingleton().logMessage(" Hitting (2) :"+myRay.getInfoAt(1).mBody->getOgreNode()->getName());
}
else
{
// Ok ! We have an hit
' // The distance to the hit is: myRay.getFirstHit().mDistance;
//LogManager::getSingleton().logMessage(" Hitting :"+myRay.getFirstHit().mBody->getOgreNode()->getName());
}
}


Hope it helps (not like my first answer :wink: )

BTW, I really really like Ash ! :) Do you expect to release a demo?

Hansel

22-06-2006 13:53:23

Thanks abecam ;)

I've found in the samples the terrain code and it uses rayscenequery.

updateRay.setOrigin(mCamera->getPosition());
updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
raySceneQuery->setRay(updateRay);
RaySceneQueryResult& qryResult = raySceneQuery->execute();
RaySceneQueryResult::iterator i = qryResult.begin();
if (i != qryResult.end() && i->worldFragment)
{
SceneQuery::WorldFragment* wf = i->worldFragment;
mCamera->setPosition(mCamera->getPosition().x,
i->worldFragment->singleIntersection.y + 10,
mCamera->getPosition().z);
}



This is exactly what I need (the camera has always height = 10 over the terrain). The problem now is how to calculate that intersection point, because the terrain sample uses terrainscenemanager but my scene is a normal mesh launched as entity, it's not launched from a file that uses a heightmap.


std::string terrain_cfg("terrain.cfg");
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
terrain_cfg = mResourcePath + terrain_cfg;
#endif
mSceneMgr -> setWorldGeometry( terrain_cfg );



How can I use the same or similar code with my scene? Any idea? :D




pd.- I released a demo a month ago but it was a teaser demo, just to show 3-4 ideas I had. In two weeks more or less a second demo will be released :wink:

abecam

23-06-2006 13:24:59

Then, my code was also done with a "entity"-world, in a TreeCollision format. Basically it gives the list of all body encountered, and then you can have the infos on all, and choose what to do. In my case I wanted the vehicle to levitate on every thing, so I only recovered the distance to the first collision. From the doc:



Public Attributes
Ogre::Real mDistance
dist from point1 of the raycast, in range [0,1].
OgreNewt::Body * mBody
pointer to body intersected with
int mCollisionID
collision ID of the primitive hit by the ray (for compound collision bodies)
Ogre::Vector3 mNormal
normal of intersection.


So if your terrain is a simple entity, you find it easily. The terrain sample is from Ogre, if I remember well (I used it also), the BasicRay is part of ONewt.
Not sure if I answered the question... :)

An update of my code for a mCamera to ground ray:


OgreNewt::BasicRaycast myRay(me->getWorld(),mCamera->getPosition(), mCamera->getPosition() + Vector3::NEGATIVE_UNIT_Y * 20 ); // From the camera position to 20 units belows (it is absolute, the ray is not infinite, it goes only from start to end)

if (myRay.getHitCount() > 0) // If the camera is not inside a collision body !!! Or you have to do as my previous code
{

// Ok ! We have an hit
// The distance to the hit is: myRay.getFirstHit().mDistance;


// If you want to make sure it is the right body you have hit, you can use myRay.getInfoAt(iHittedBody).mBody->getOgreNode()->getName() to know which body you have, in order
}


Seems easier :)

Hansel

23-06-2006 17:40:47

Thank you very much abecam, it works very, very fine :D

lonwolf

27-06-2006 12:27:45

ok that i tryed myself but as you sayd the distance is between [0,1]

and for example if you want to move the character down the Y axis till it hits the ground (intersection Point) . Im afraid with sePotion isnt workin..

now the main question: let me understand.
1. you create the ray.
2. you fire the ray.
3. you get the distance till the first hit

great and 4. how do you move your char to put it on the intersection point?? any chunk of code to make that clear is greatly appreciated thankz and pls help im confused with that mDistance :? :oops: :(

lonwolf

01-07-2006 11:31:03

hey @Hansel
ash is bouncing because of the resultant of the upvector and your move vector.. its just a vector pshisics problem..
An the solution in simple: if u have an upVector your move vector MUST'NT be paralell to the ground and perpendicular on the upVector.. it must be pointing to the ground aprox 45 degrees under the "logical" position or even lower.. that will make him have a relativily "not bouncy" movement.. ill try that myself but its actually logical your Ash is movin like a rabbit :lol: (bouncin that is :D )

il release a workin code after il get one.. cyaz :wink:

Hansel

02-07-2006 10:11:02

ok that i tryed myself but as you sayd the distance is between [0,1]

and for example if you want to move the character down the Y axis till it hits the ground (intersection Point) . Im afraid with sePotion isnt workin..

now the main question: let me understand.
1. you create the ray.
2. you fire the ray.
3. you get the distance till the first hit

great and 4. how do you move your char to put it on the intersection point?? any chunk of code to make that clear is greatly appreciated thankz and pls help im confused with that mDistance :? :oops: :(


I can't understand exactly what you want. Do yo want to use one ray to clamp your character to the terrain when you move it? In that case you need to throw the ray from your character to the terrain, calculate the distance between the intersection point and your charcater and, if that distance is, for example, bigger than 0 (is not exactly 0, perhaps 0.001+), you need to decrease a little bit (for example 0.1, depends of the scale of you character). Repeat the same steps until distance <= 0 ;)

lonwolf

02-07-2006 10:56:26

aha so its looking like


while(mDistance>0)
{
Vector3 pos = node->getPosition();
pos.y-=1;
node->setPosition(pos);
//fire the ray again and update mDistance etc
}


right? i was hoping it would return the exact value like the RayCasting in Ogre... but its gona be the hard way. :D thankz i needed some confirmation about this topic :? :lol: