[Solved] Stop scripted pawn rotation?

Discussions about Coding and Scripting
Post Reply
User avatar
ANUBITEK
Adept
Posts: 261
Joined: Sun Dec 28, 2014 1:10 am
Location: Anubitek

[Solved] Stop scripted pawn rotation?

Post by ANUBITEK »

First off, cross posting from OldUnreal. Trying not to do that as often (ayy) but I have a question for a pawn and was curious if the answer would be different due to any major differences between base UT and U227 code. As far as I can tell though, rotation/vector movement seem to be pretty much the same.

I'm working on a feature for a camera pawn the player can see through (it is just a third person camera). I am trying to implement a new feature that tells the camera to not change its X, Y, or Z positions but to rotate in order to track the player at any angle. I just need it to stay at a single point and track in a 360 degree rotation, like the security cameras in Deus Ex but without sweeping back and forth to track the player.

The issue is not only is the camera not rotating to follow the player if they go past it, but it is instead tracking them relative to their Z coordinates.

If I move left, the camera also moves left in a 1:1 tracking motion.
If I move right, same.
If I move toward the camera, it only changes its Z position based on how close I get to it.
If I jump, the camera jumps too.
If I run past the camera, it will still move 1:1 with my left to right movements (but mirrored because I'm behind the camera) and will adjust its Z position, but it will not rotate to face the player.

Code: Select all

var PlayerPawn LocalPlayer;
var() float    CamDistance;
var float      TargetDistance;

auto state Camera
{
    event Tick( float DeltaTime )
    {
        local vector CamLoc;
        local vector NewLoc;
//		local rotator View;
        local int OldYaw;
        local int OldPitch;

        if ( LocalPlayer == none )
            return;
        switch CameraMode
        {
//=============================================================================
            case CM_TrackFixed360: // The camera only tracks the player in 360 degress.
				NewLoc = Location; // Location is set through a trigger, which changes the camera's state after assigning new location.
				DesiredRotation = rotator( LocalPlayer.Location - Location); // Camera should track player.
				SetLocation( NewLoc );
                break;
//=============================================================================
Last edited by ANUBITEK on Wed Jan 20, 2016 10:46 pm, edited 2 times in total.
<<| http://uncodex.ut-files.com/ |>>

Code reference for UGold, UT99, Unreal2, UT2k3, UT3
Additional Beyond Unreal Wiki Links
wiki.beyondunreal.com/Legacy:Console_Bar
wiki.beyondunreal.com/Exec_commands#Load
wiki.beyondunreal.com/Legacy:Exec_Directive#Loading_Other_Packages
wiki.beyondunreal.com/Legacy:Config_Vars_And_.Ini_Files
wiki.beyondunreal.com/Legacy:INT_File
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Scripted pawn rotation?

Post by JackGriffin »

Can't you just freeze the camera by forcing it's momentum to zero?
So long, and thanks for all the fish
User avatar
ANUBITEK
Adept
Posts: 261
Joined: Sun Dec 28, 2014 1:10 am
Location: Anubitek

Re: Scripted pawn rotation?

Post by ANUBITEK »

I actually wouldn't know how to do that through a switch. Mind giving an example?
<<| http://uncodex.ut-files.com/ |>>

Code reference for UGold, UT99, Unreal2, UT2k3, UT3
Additional Beyond Unreal Wiki Links
wiki.beyondunreal.com/Legacy:Console_Bar
wiki.beyondunreal.com/Exec_commands#Load
wiki.beyondunreal.com/Legacy:Exec_Directive#Loading_Other_Packages
wiki.beyondunreal.com/Legacy:Config_Vars_And_.Ini_Files
wiki.beyondunreal.com/Legacy:INT_File
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Scripted pawn rotation?

Post by JackGriffin »

This is how I did it in the antiboost part of MH2

Code: Select all

   if(bUseAntiBoost)
   {
      if(Victim != None && InstigatedBy != None)
      {
         if (InstigatedBy.IsA('PlayerPawn') && Victim.IsA('PlayerPawn'))
         {
	    Momentum = Vect(0,0,0);
            ActualDamage = 0;
            if (string(DamageType)=="RedeemerDeath")
            {
	       Velocity = Vect(0,0,0);
	       Victim.Velocity = (Victim.Velocity * 0);
            }
         }
      }
   }
That's what I meant. Just clamp it to one spot. It will still be able to rotate, just not move.
So long, and thanks for all the fish
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Scripted pawn rotation?

Post by Barbie »

Have you had a look at the code for the Automatic Cannons? Their tracking of an enemy is similar to your task.
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
ANUBITEK
Adept
Posts: 261
Joined: Sun Dec 28, 2014 1:10 am
Location: Anubitek

Re: Scripted pawn rotation?

Post by ANUBITEK »

Do you mean the machine gun turrets like the ones on AS-HiSpeed?
<<| http://uncodex.ut-files.com/ |>>

Code reference for UGold, UT99, Unreal2, UT2k3, UT3
Additional Beyond Unreal Wiki Links
wiki.beyondunreal.com/Legacy:Console_Bar
wiki.beyondunreal.com/Exec_commands#Load
wiki.beyondunreal.com/Legacy:Exec_Directive#Loading_Other_Packages
wiki.beyondunreal.com/Legacy:Config_Vars_And_.Ini_Files
wiki.beyondunreal.com/Legacy:INT_File
User avatar
Barbie
Godlike
Posts: 2802
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Scripted pawn rotation?

Post by Barbie »

LannFyre wrote:Do you mean the machine gun turrets like the ones on AS-HiSpeed?
Yes, for example. But AS-HiSpeed's MinigunCannon is a sub class of TeamCannon where the code of interest is in.
Cannon also has a player tracking functionality.
If you don't have access to the source code, I've found it online here.

(As a reminder the class hierarchies:
Object>Actor>Pawn>StationaryPawn>TeamCannon>MinigunCannon
Object>Actor>Decoration>Cannon)
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
MrLoathsome
Inhuman
Posts: 958
Joined: Wed Mar 31, 2010 9:02 pm
Personal rank: I am quite rank.
Location: MrLoathsome fell out of the world!

Re: Scripted pawn rotation?

Post by MrLoathsome »

Maybe try a call to SetRotation in between where you assign DesiredRotation and the SetLocation call.?
Or a TurnTo() *Edit: TurnTowards() ? I forget.

Take Jacks suggestion to anchor the thing if needed. Or mix them up if you want it moving and tracking.
blarg
User avatar
ANUBITEK
Adept
Posts: 261
Joined: Sun Dec 28, 2014 1:10 am
Location: Anubitek

Re: Scripted pawn rotation?

Post by ANUBITEK »

Of course, the problem wasn't in the pawn itself but in the trigger that changes what mode the camera should be using. I am so mad at myself because I can't into logic. Ultimately CM_TrackFixed360 does work, the only issue was. . . I think the camera was being told to go to two cases at once and it was overriding what was set through CM_TrackFixed360. At this moment, I feel incredibly dumb. First, this is what works (note velocity wasn't required but I'm thinking of including it anyway):

Code: Select all

//=============================================================================
            case CM_TrackFixed360:
//				Velocity = vect(0,0,0);
				NewLoc = Location;
				DesiredRotation = rotator( LocalPlayer.Location - Location);
				SetRotation( DesiredRotation );
				SetLocation( NewLoc );
                break;
//=============================================================================
            case CM_TrackFixedX: // The camera tracks the local player at a fixed x and y point, moving only by it's z axis.
                OldYaw = DesiredRotation.Yaw; // Conserve DesiredRotation's yaw
				NewLoc.X = Location.X;
                NewLoc.Y = LocalPlayer.Location.Y - vector(DesiredRotation).Y * VSize(Location - LocalPlayer.Location);
                NewLoc.Z = LocalPlayer.Location.Z - vector(DesiredRotation).Z * VSize(Location - LocalPlayer.Location);
                DesiredRotation.Yaw = OldYaw; // Restore yaw
                SetLocation( NewLoc );
                break;
//=============================================================================
This is where the issue was, in RPG_CameraSwitcher (which was communicating with RPG_Camera):

Code: Select all

		case CM_TrackFixed360:
			log("Changing CameraMode to CM_TrackFixed360");
			ActiveCamera.CameraMode = CM_TrackFixed360;
//			AND I DIDN'T INCLUDE A BREAK JESUS I'M DUMB
Here is the whole function, before it was fixed:

Code: Select all

function SetCameraMode()
{
	if ( ActiveCamera == none )
		return;
	switch NewCameraMode
	{
		case CM_Fixed1:
			log("Changing CameraMode to CM_Fixed1");
			ActiveCamera.CameraMode = CM_Fixed1;
		case CM_Fixed2:
			log("Changing CameraMode to CM_Fixed2");
			ActiveCamera.CameraMode = CM_Fixed2;
			break;
		case CM_TrackFixed360:
			log("Changing CameraMode to CM_TrackFixed360");
			ActiveCamera.CameraMode = CM_TrackFixed360;
		case CM_TrackFixedX:
			log("Changing CameraMode to CM_TrackFixedX");
			ActiveCamera.CameraMode = CM_TrackFixedX;
			break;
		case CM_TrackFixedY:
			log("Changing CameraMode to CM_TrackFixedY");
			ActiveCamera.CameraMode = CM_TrackFixedY;
			break;
		case CM_TrackFixedXY:
			log("Changing CameraMode to CM_TrackFixedXY");
			ActiveCamera.CameraMode = CM_TrackFixedXY;
			break;
		case CM_TrackCustom:
			log("Changing CameraMode to CM_TrackCustom");
			ActiveCamera.CameraMode = CM_TrackCustom;
			break;
		default:
			break;
	}
}
<<| http://uncodex.ut-files.com/ |>>

Code reference for UGold, UT99, Unreal2, UT2k3, UT3
Additional Beyond Unreal Wiki Links
wiki.beyondunreal.com/Legacy:Console_Bar
wiki.beyondunreal.com/Exec_commands#Load
wiki.beyondunreal.com/Legacy:Exec_Directive#Loading_Other_Packages
wiki.beyondunreal.com/Legacy:Config_Vars_And_.Ini_Files
wiki.beyondunreal.com/Legacy:INT_File
Post Reply