camera-independent 3rd-person movement?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
vAethor
Posts: 93
Joined: Wed May 10, 2017 4:10 pm

camera-independent 3rd-person movement?

Post by vAethor »

I have a 3rd-person WAD going with my friend, and am thinking of fine-tuning the 3rd-person camera script I wrote months ago to make Doomguy's movement independent of the camera, if possible.

Basically I am aiming for more of a 3D platformer-style camera, like what many PS1 and N64 games used. Sonic Robo-Blast 2 managed to do it on Doom Legacy, so I'd assume GZDoom would have a way to do it too.

My code is currently a simple chasecam script I got from the wiki. The ACS for it is below.

Code: Select all

//Third person camera simulation.
//solarsnowfall

#include "zcommon.acs"

#define C_TID		1000	//Default camera tid
#define MAX_R		192	//Maximum radius (or distance from the player) (128 def)
#define ADJUST_R	8	//Amount to adjust the camera by (8 def)
#define VIEW_HEIGHT	61.0	//The approximate height of the player's view (41 def)

bool cam_mode[8];		//Variable for turning the camera on or off.
	
Script 1 ENTER
{
	cam_mode[PlayerNumber ()] = ON;
	ACS_ExecuteAlways (3, 0, PlayerNumber ());
}

Script 2 RESPAWN
{
	cam_mode[PlayerNumber ()] = ON;
	ACS_ExecuteAlways (3, 0, PlayerNumber ());
}

Script 3 (int p_num)
{
	int r = MAX_R;
	
	while (cam_mode[p_num] == ON)
	{	
		int a = GetActorAngle (0);
		int p = GetActorPitch (0);
		int x = GetActorX (0);
		int y = GetActorY (0);
		int z = GetActorZ (0) + VIEW_HEIGHT;
		int xyr = r * cos (p) >> 16;
		
		if (!ThingCountName ("ChaseCam", C_TID+p_num))
		{
			while (!Spawn ("ChaseCam", x-cos(a)*xyr, y-sin(a)*xyr, z+sin(p)*r, C_TID+p_num, a >> 8) && r > 0)
			{
				r -= ADJUST_R;
				xyr = cos (p) * r >> 16;
			}
			
			if (ThingCountName ("ChaseCam", C_TID + p_num))
				ChangeCamera (C_TID + p_num, 0, 0);
			else
			{
				cam_mode[p_num] = OFF;
				print (s:"Camera script failed to initialize.");
			}
		}
		
		
			        else
		{
			while (!SetActorPosition (C_TID+p_num, x-cos(a)*xyr, y-sin(a)*xyr, z+sin(p)*r, 0) && r > 0)
			{
				r -= ADJUST_R;
				xyr = cos (p) * r >> 16;
			}
			
			SetActorAngle (C_TID + p_num, a);
			SetActorPitch (C_TID + p_num, p);
			
			if (r < MAX_R) 
                              r += ADJUST_R;
		}
		
		delay (1);
	}
}

Script 4 DEATH
{
	cam_mode[PlayerNumber ()] = OFF;
	Thing_Remove (C_TID + PlayerNumber ());
}

Script 5 (int p_num) DISCONNECT
{
       cam_mode[p_num] = OFF;
       Thing_Remove (C_TID + p_num);
}

I know almost no ACS and simply copied this from the Zdoom Wiki intending to learn what everything does later. While I wait for replies I can probably do some research.

Edit: I understand the gist of what the script does. My guess is changing some values in this block would do something.

Code: Select all

		while (!SetActorPosition (C_TID+p_num, x-cos(a)*xyr, y-sin(a)*xyr, z+sin(p)*r, 0) && r > 0)
			{
				r -= ADJUST_R;
				xyr = cos (p) * r >> 16;
			}
			
			SetActorAngle (C_TID + p_num, a);
			SetActorPitch (C_TID + p_num, p);
			
			if (r < MAX_R) 
                              r += ADJUST_R;
		}
		
		delay (1);
I commented out the SetActorAngle() line and got strange results, not what I was looking for. But I think I may be onto something.
Post Reply

Return to “Scripting”