Example #1
0
void CPathFind::StepTo(position_t* pos, bool run)
{

    float speed = GetRealSpeed();

    int8 mode = 2;

    if (!run)
    {
        mode = 1;
        speed /= 2;
    }

    float stepDistance = ((float)speed / 10) / 2;
    float distanceTo = distance(m_PTarget->loc.p, *pos);

    // face point mob is moving towards
    LookAt(*pos);

    if (distanceTo <= stepDistance ||
        (m_pathFlags & PATHFLAG_SLIDE) && distance(m_originalPoint, m_PTarget->loc.p) < m_distanceFromPoint)
    {
        m_distanceMoved += distanceTo;

        m_PTarget->loc.p.x = pos->x;
        m_PTarget->loc.p.y = pos->y;
        m_PTarget->loc.p.z = pos->z;

    }
    else
    {
        m_distanceMoved += stepDistance;
        // take a step towards target point
        float radians = (1 - (float)m_PTarget->loc.p.rotation / 256) * 2 * M_PI;

        m_PTarget->loc.p.x += cosf(radians) * stepDistance;

        m_PTarget->loc.p.y = pos->y;

        m_PTarget->loc.p.z += sinf(radians) * stepDistance;

    }


    m_PTarget->loc.p.moving += ((0x36 * ((float)m_PTarget->speed / 0x28)) - (0x14 * (mode - 1)));

    if (m_PTarget->loc.p.moving > 0x2fff)
    {
        m_PTarget->loc.p.moving = 0;
    }

    m_PTarget->updatemask |= UPDATE_POS;
}
Example #2
0
void CPathFind::StepTo(position_t* pos, bool run)
{

	float speed = GetRealSpeed();

	int8 mode = 2;

	if (!run)
	{
		mode = 1;
		speed /= 2;
	}

	// face point mob is moving towards
	LookAt(*pos);

	float stepDistance = ((float)speed / 10) / 2;
	float distanceTo = distance(m_PTarget->loc.p, *pos);

	// if i'm going to overshoot the checkpoint just put me there
	if (distanceTo <= stepDistance)
	{
		m_distanceMoved += distanceTo;

		m_PTarget->loc.p.x = pos->x;
		m_PTarget->loc.p.y = pos->y;
		m_PTarget->loc.p.z = pos->z;

	}
	else
	{
		m_distanceMoved += stepDistance;
		// take a step towards target point
		float radians = (1 - (float)m_PTarget->loc.p.rotation / 256) * 2 * M_PI;

		m_PTarget->loc.p.x += cosf(radians) * stepDistance;

		m_PTarget->loc.p.y = pos->y;

		m_PTarget->loc.p.z += sinf(radians) * stepDistance;

	}

	m_PTarget->loc.p.moving += ((0x36 * ((float)m_PTarget->speed / 0x28)) - (0x14 * (mode - 1)));

	if (m_PTarget->loc.p.moving > 0x2fff)
	{
		m_PTarget->loc.p.moving = 0;
	}
    m_PTarget->updatemask |= UPDATE_POS;
}