Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Osprey teleports to world origin if it isn't moving at all #3260

Open
SamVanheer opened this issue Mar 14, 2022 · 0 comments
Open

Osprey teleports to world origin if it isn't moving at all #3260

SamVanheer opened this issue Mar 14, 2022 · 0 comments

Comments

@SamVanheer
Copy link

If a monster_osprey isn't moving at all it will teleport to the world origin due to a divide by zero error.

Change this:

halflife/dlls/osprey.cpp

Lines 415 to 424 in c7240b9

float scale = 1.0 / m_dTime;
float f = UTIL_SplineFraction( t * scale, 1.0 );
Vector pos = (m_pos1 + m_vel1 * t) * (1.0 - f) + (m_pos2 - m_vel2 * (m_dTime - t)) * f;
Vector ang = (m_ang1) * (1.0 - f) + (m_ang2) * f;
m_velocity = m_vel1 * (1.0 - f) + m_vel2 * f;
UTIL_SetOrigin( pev, pos );
pev->angles = ang;

To this:

//Only update if delta time is non-zero. It's zero if we're not moving at all (usually because we have no target).
if (m_dTime != 0)
{
	float scale = 1.0 / m_dTime;

	float f = UTIL_SplineFraction(t * scale, 1.0);

	Vector pos = (m_pos1 + m_vel1 * t) * (1.0 - f) + (m_pos2 - m_vel2 * (m_dTime - t)) * f;
	Vector ang = (m_ang1) * (1.0 - f) + (m_ang2)*f;
	m_velocity = m_vel1 * (1.0 - f) + m_vel2 * f;

	UTIL_SetOrigin(pev, pos);
	pev->angles = ang;
}

This change disables the movement update logic if the time between movement positions is zero. This value is zero if the Osprey isn't moving at all, such as when it has no target or when its speed is 0. It causes the scale variable to become infinity and the calculated vectors to become not-a-number (NaN) values which results in the Osprey moving to the world origin.

This also applies to the Black Ops Osprey in Opposing Force.

SamVanheer added a commit to twhl-community/halflife-op4-updated that referenced this issue Mar 15, 2022
…eSoftware/halflife#3259

Fix Black Ops Osprey teleporting to world origin if it isn't moving at all Resolves ValveSoftware/halflife#3260
Fix Black Ops Osprey not firing trigger targets Resolves ValveSoftware/halflife#3261
@SamVanheer SamVanheer reopened this May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants