Orientation trouble

Started by
16 comments, last by haegarr 12 years, 8 months ago
So I am stuck :(
Are there any alternatives to driving the object physically with a path?
Thanks
Jack
Advertisement
But you understand what problem I see within that approach? Maybe I'm missing something, but until now I'm quite sure.

What happens if you try something like the following:

void CrowdEntity::Update(float deltaTime)
{
const float ENTITY_INFLUENCE_RADIUS = 100.0f;
const float NEIGHBOR_REPULSION = 50.0f;
const float ENTITY_SPEED = 200.0f;
const float ENTITY_SIZE = 100.0f;

D3DXVECTOR3 forceToGoal = m_goal - m_position;

//Has goal been reached?
if(D3DXVec3Length(&forceToGoal) < ENTITY_INFLUENCE_RADIUS)
{
//Pick a new random goal
m_goal = GetRandomLocation();
forceToGoal = m_goal - m_position;
}
D3DXVec3Normalize(&forceToGoal, &forceToGoal);

//Get neighbors
vector<CrowdEntity*> neighbors;
m_pCrowd->GetNeighbors(this, ENTITY_INFLUENCE_RADIUS, neighbors);

//Avoid bumping into close neighbors
D3DXVECTOR3 forceAvoidNeighbors(0.0f, 0.0f, 0.0f);
for(int i=0; i<(int)neighbors.size(); i++)
{
D3DXVECTOR3 toNeighbor = neighbors->m_position - m_position;
float distToNeighbor = D3DXVec3Length(&toNeighbor);

toNeighbor.y = 0.0f;
float force = 1.0f - (distToNeighbor / ENTITY_INFLUENCE_RADIUS);
forceAvoidNeighbors += -toNeighbor * NEIGHBOR_REPULSION * force;

//Force move intersecting entities
if(distToNeighbor < ENTITY_SIZE)
{
D3DXVECTOR3 center = (m_position + neighbors->m_position) * 0.5f;
D3DXVECTOR3 dir = center - m_position;
D3DXVec3Normalize(&dir, &dir);

//Force move both entities
m_position = center - dir * ENTITY_SIZE * 0.5f;
neighbors->m_position = center + dir * ENTITY_SIZE * 0.5f;
}
}

//Sum up forces
D3DXVECTOR3 acc = forceToGoal + forceAvoidNeighbors;
D3DXVec3Normalize(&acc, &acc);

//Update velocity & position
m_velocity += acc * deltaTime;
D3DXVec3Normalize(&m_velocity, &m_velocity);
m_position += m_velocity * ENTITY_SPEED * deltaTime;
}


Please tell us the sense of PathFind(). What is it computing, and what is the purpose of the resulting path?


EDIT: direction of forceToGoal negated, and re-computation of that value on new goal inserted.
Wow, yeah. This is the original program... :)
The pathfind() function just computes a straight path with no obstacles for the time being.
I need a pre-computed path because I don't want the objects to wander freely....
Do you want me to send the whole stuff to you to have a look at it? It's very small
Thanks
Jack

Wow, yeah. This is the original program... :)

Ohh. Okay. So you already knew that version ;) However, does it show the same problem? Probably not, so the problem is really in the mix-up as said!?


The pathfind() function just computes a straight path with no obstacles for the time being.
I need a pre-computed path because I don't want the objects to wander freely....

Well, they never wander freely because they wander towards a goal. Do you want them to reach the goal not on a straight line (when ignoring the avoidances here) but more-or-less along a path prescription? So you can give them a curved way, for example? Is that the intention?


Do you want me to send the whole stuff to you to have a look at it? It's very small

Not for the moment, because I still haven't understood the whys and whats, and I probably won't see this in the code.
Can the objects dodge static obstacles with this coding? I don't need a pathfinder?
But i need a precise path. because it's a computational project...
The path comprises of straight and curved portions
Thanks
Jack

Can the objects dodge static obstacles with this coding? I don't need a pathfinder?

The objects can avoid dynamic obstacles (just the other moving objects) and hence I'd say, yes, they can avoid static obstacles, too. Maybe it requires some tweaking though.

The implemented method is this: The object tries to go step straight into the direction of the goal. But there is an obstacle in the way. If the obstacle is far enough then the objects does the step as-is. If it is too close then the object gets a pulse into a direction to avoid a collision.


But i need a precise path. because it's a computational project...
The path comprises of straight and curved portions

If the paths of all moving objects are pre-defined, then don't use dynamic avoidance and physical motion. Use a timeline animation instead, so you'll have all under control. Run the animation until you see a collision, then tweak the animation curves as needed.
Excuse me for my dumbness. But what is a timeline animation specifically? And also, Are there any good web references for me to take a look at up to this point? And of course, source code Thanks Jack
With timeline animation I mean that the placements of all objects are pre-defined, manually tweaked, driven by a timeline.

Should the environment be dynamic? Should the situation be evaluated each frame, and the movement adapted accordingly? I.e. the movement is computed on-the-fly? Hence the path will look zigzag like but smoothed because sudden changes in velocity cannot occur. Then there is no sense in computing a path in advance. An addition may be that the path an agent can choose is constraint by the environment.

Or else ... Should the path be computed in advance? So that it is defined, all situations in the environment predetermined? No surprising encounters? Then a hand tweaked timeline animation can be used, yielding in a totally deliberate movement.

Your OP contains a mix of both. It is just that mix that makes your code snippet not work. Hence my question: What is the goal? Why do you think you need both approaches together?

This topic is closed to new replies.

Advertisement