//============================================================================
This should work as a good example for checking the positions between two Actors and comparing rotations.
Code: Select all
event Tick( float DeltaTime)
{
local [CAMERA] LocalCam;
local [ACTOR] TargetActor;
local Vector V, X, Y, Z;
local rotator R;
local byte SpriteIndex;
local int i, j, Max;
ForEach AllActors (class'[INSERT VIEWPORT-OWNER HERE]', LocalCam)
{
if ( LocalCam == none )
return;
break;
}
[...]
if ( TargetActor != none && TargetActor .DrawType == DT_Sprite
&& LocalCam != none )
{
AdjustDirIndex(TargetActor, LocalCam, SpriteIndex);
[...]
Code: Select all
final function int AdjustDirIndex(Actor SpritePawn, [VIEWPORT OWNER] Camera, out int AnimDir)
{
local Rotator R1,R2;
// MAX_WORD is 0b1111111111111111 (65535, 16 bits)
// MAX_DIR is 0b0000000000000111 (7, 3 bits)
R1 = sAnimated.Rotation;
R2 = Rotator(Camera.Location - sAnimated.Location);
AnimDir = ( ( (R1.Yaw - R2.Yaw) & 65535) + 4096) >> 13;
return AnimDir;
}
If you want some more info on this beyond the solution to grabbing the rotation values, head to this topic:
viewtopic.php?f=15&t=11730&p=94432#p94432
//============================================================================
So I shelved the code I was working on, which was doing what I needed based on if the actor was facing "North", but any other direction and I would yield strange results.
I found the "Old Scrap Code" below was checking between the range of 1.0 and -1.0 based on the relative position of the camera to the actor, 1.0 being the front of the actor that was being tracked for sprite changes, and behind the actor was -1.0 (if you were 45 degrees to the actor on either its left or right, you would get a 0.0).
I'm willing to bet that this could have easily been fixed, but as Gustavo pointed out, if the Camera was above the actor in question, I got a dot result that made the sprite act strangely because I THINK that it is doing the math independent of certain limits that should restrict results that occur due to vertical position of camera to the tracked actor, but I have no idea how to do that. Why does it do this by the way? I have more questions about how Dot product works in Unrealscript if anyone wants to discuss it.
Code: Select all
/*if ( (X dot Normal(V) >= 0.75) && (X dot Normal(V) <= 1.0) ) // 0.125
{
SpriteIndex = 1;
log("1: "$ X dot Normal(V));
}
if ( (X dot Normal(V) >= 0.25) && (X dot Normal(V) < 0.75) ) // 0.25
{
SpriteIndex = 2;
log("2: "$ X dot Normal(V));
}
if ( (X dot Normal(V) >= -0.25) && (X dot Normal(V) < 0.25) ) // 0.25
{
SpriteIndex = 3;
log("3: "$ X dot Normal(V));
}
if ( (X dot Normal(V) >= -0.75) && (X dot Normal(V) < -0.25 ) ) // 0.125
{
SpriteIndex = 4;
log("4: "$ X dot Normal(V));
}
if ( (X dot Normal(V) >= -1.0) && (X dot Normal(V) < -0.75 ) ) // 0.125
{
SpriteIndex = 5;
log("5: "$ X dot Normal(V));
}