Steering behaviors - Seek


  • I'm trying to get a seek behavior working, and can't seem to get the results needed. Any help?

    Here's my seek method.

    XMFLOAT3 Steering3D::SmoothSeek(XMFLOAT3 pos, XMFLOAT3 target, XMFLOAT3 velocity, float speed)
    	// Convert.
    	XMVECTOR posV = XMLoadFloat3(&pos);
    	XMVECTOR targetV = XMLoadFloat3(&target);
    	XMVECTOR velocityV = XMLoadFloat3(&velocity);
    	// Normalize.
    	XMVECTOR desiredVelocityV = XMVector3Normalize(targetV - posV) * speed;
    	XMVECTOR steeringV = desiredVelocityV - velocityV;
    	// Re-convert.
    	XMFLOAT3 steering;
    	XMStoreFloat3(&steering, steeringV);
    	return steering;

    And here's the code, where I add it to the entity

    XMFLOAT3 steering = m_steer->SmoothSeek(m_pos, XMFLOAT3(0.0f, 0.0f, 10.0f), m_velocity, 0.005f);
    m_velocity.x += steering.x;
    m_velocity.y += steering.y;
    m_velocity.z += steering.z;
    m_pos.x += m_velocity.x; 
    m_pos.y += m_velocity.y; 
    m_pos.z += m_velocity.z;

    Basically, I'm trying to get the entity to move like the second example in this link:http://gamedev.tutsplus.com/tutorials/implementation/understanding-steering-behaviors-seek/

    It should seek smoothly to the target, but it doesn't. Any help?

    [url=http://catalog.create.msdn.com/en-US/GameDetails.aspx?catalogEntryId=5cbacba6-05c2-4c33-9005-6cc80c8d5753&type=1]Bible Trivia Avatar Edition[/url], currently in review.

    Thursday, November 21, 2013 11:22 PM


  • you're right that you need to consider what you want your new velocity to be.  But you also need to consider what amount of acceleration will take you there.  In your example, you take the desired velocity minus the current velocity and add that to the current velocity.  That basically sets your velocity to the desired velocity in one shot.  Should work perfectly, so long as speed is set to something reasonable.

    Let me think out loud for a moment:

    The one thing missing from your equations is time.

    pos += velocity * time.

    velocity += acceleration * time.

    Since it's missing, then we assume the change in time is 1, so I guess your units are in frames.

    The desired speed is 0.005 units per frame.

    the desired velocity is a vector in the direction of the target relative to your current position at the desired speed.  That's right.

    The change in velocity "steering" is simply the desiredVelocity - the velocity, which doesn't account for any maximum amount of acceleration or anything.   You basically get infinite acceleration - infinite force applied instantaneously.  So I assume what you are observing is that the model just goes directly toward the target at the given speed, with no smoothness.  Right?

    I'd normalize this steeringV value (it has the right direction) but give it a magnitude that accounts for the maximum acceleration you can apply in a frame (akin to the maximum force you can apply.)

    Tuesday, November 26, 2013 2:11 PM