Actor rotation (value clamping)
Posted: Tue Sep 27, 2016 10:38 am
Got a math question. I need to understand a concept before I go rooting around in some math code. When I took apart the turret in UT, I grabbed some rotation code in a timer:
What happens in the code is the enemy (player) has already been found, with each call of timer() based on the turret's fire rate the turret rotates to face the player then shoot() is called. But my question has to do with this particular snippet of the above code:
Can anyone explain to me the purpose of the additional number "65535", as well as why the single "&" operator is being used? I know it has to do with bit shifting, but I don't understand why it is used.
>>>>>>>>>>>>>>>>>>>>
Mobile edit:
It just occured to me that the value 65535 is 256^2, is this the extent of what the rotational value of an object can reach before it goes back to 0?
>>>>>>>>>>>>>>>>>>>>
On a related note, found something for determining relative rotation, though it appears to only covers four angles of an actor.
https://forums.unrealengine.com/showthr ... ite-system
Anyone got the time to direct me to an example of Dot that could make sense to me? Looking at the Vectors page unfortunately leaves me stumped on Dot as it is used in this context.
Turret Timer
Code: Select all
function Timer()
{
if (Enemy == none || Enemy.bDeleteMe || Enemy.Health <= 0)
EnemyNotVisible();
else
{
DesiredRotation = rotator(Enemy.Location - Location);
DesiredRotation.Yaw = DesiredRotation.Yaw & 65535;
if (LineOfSightTo(Enemy))
{
if (bFired && DesiredRotation.Pitch < 2000 &&
(Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) < 1000 ||
Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) > 64535))
{
Shoot();
}
else
{
bFired = true;
SetTimer(FireRate, true);
}
}
}
}
Code: Select all
DesiredRotation = rotator(Enemy.Location - Location);
DesiredRotation.Yaw = DesiredRotation.Yaw & 65535;
if (LineOfSightTo(Enemy))
{
if (bFired && DesiredRotation.Pitch < 2000 &&
(Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) < 1000 ||
Abs(DesiredRotation.Yaw - (Rotation.Yaw & 65535)) > 64535))
>>>>>>>>>>>>>>>>>>>>
Mobile edit:
It just occured to me that the value 65535 is 256^2, is this the extent of what the rotational value of an object can reach before it goes back to 0?
>>>>>>>>>>>>>>>>>>>>
On a related note, found something for determining relative rotation, though it appears to only covers four angles of an actor.
https://forums.unrealengine.com/showthr ... ite-system
Spoiler
Code: Select all
Sprite A if , Dot(Enemy forward vector , (playerLocation - EnemyLocation).Normalized) >0.7
Sprite D if , Abs( Dot(Enemy forward vector ,(playerLocation - EnemyLocation).Normalized) )<0.7 && Dot(enemy Right Vectorc,(playerLocation - EnemyLocation).Normalized)<0
Sprite B if ,Abs( Dot(Enemy forward vector ,(playerLocation - EnemyLocation).Normalized) )<0.7 && Dot(enemy Right Vectorc,(playerLocation - EnemyLocation).Normalized)>0
Sprite C if , Dot(Enemy forward vector,(playerLocation - EnemyLocation).Normalized) <-0.7