Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Issue with converting a facing to a Vector3.Z value to look at
Issue with converting a facing to a Vector3.Z value to look at [message #464420] Wed, 14 March 2012 15:27 Go to next message
iRANian is currently offline  iRANian
Messages: 4308
Registered: April 2011
Karma: 0
General (4 Stars)
I'm working on a modified spectate plugin that adds a feature to automatically follow a player (by attaching the player to the head bone of the guy to follow) and also have it automatically follow the camera of the guy that's being followed, what I'm using now works with X and Y but it doesn't work correctly with the Z-height. This is what I'm using:

void Iran_Spectate_Follow_Camera_Player::Timer_Expired(GameObject *o, int number)
{
	if(number == 1)
	{
		GameObject *Player = Get_GameObj(ID);
		if(o && Player)
		{
			float facing_spectatedguy;			
			float PI = 3.14159265f;
			Vector3 pos2 = Commands->Get_Bone_Position(Player,"c head");

			facing_spectatedguy = Commands->Get_Facing(Player);

			pos2.X += 20.0f*(cos(facing_spectatedguy*PI/180));
			pos2.Y += 20.0f*(sin(facing_spectatedguy*PI/180));
			pos2.Z += 20.0f*(sin(facing_spectatedguy*PI/180)); 

			Force_Camera_Look_Player(o,pos2);
			Commands->Start_Timer(o,this,0.05f,1); // Loop
		}
	}
}


The Z-height of the camera is always off. I'm attaching the guy to the head of the other guy that he's following, according to Commands->Get_Position() this causes the position of both players be the same. I have the following two questions:

1. Is the way I calculate the Z-Height (pos2.Z in my case) correct?
2. Is it actually possible to get this correctly working, as third person and first person targeting have different Z-height from my experience?


Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases

[Updated on: Wed, 14 March 2012 15:34]

Report message to a moderator

Re: Issue with converting a facing to a Vector3.Z value to look at [message #464480 is a reply to message #464420] Fri, 16 March 2012 06:58 Go to previous messageGo to next message
Jerad2142 is currently offline  Jerad2142
Messages: 3809
Registered: July 2006
Location: USA
Karma: 6
General (3 Stars)
It's off because as he turns different directions you're doing the trig function sin and multiplying it by 20, then adding it to the height of the player you're following.

Facing only gets the Z facing of an object, not the Y and X tilt.

The best you'll be able to do is fake it (unless 4.0 gives you data exactly regarding what angle the player is looking up and down at). The easiest way to fake it that comes to mind is that you could get the difference in height between the right hand bone and the right shoulder bone of the soldier you're following. Then you just have to do some math fun:

pos2.Z += (1/HeightDifference)*20.0f;

It won't be perfect, nor will it be as good as if you actually figured out the angle between the shoulder and the hand with atan2 or something, but I'd recommend you test it with something basic first, that way if it doesn't work at all (IE: although the players arms angle to aim where they are looking on the clients computer, I'm not sure if the fds does anything more than play 3 different animations depending if your looking up, down, or straight forward, this would mean that your camera would only have 3 different heights from the player).

However, I think its worth a shot as it'd be pretty easily to implement, unless someone else has an idea.



Re: Issue with converting a facing to a Vector3.Z value to look at [message #464486 is a reply to message #464420] Fri, 16 March 2012 09:03 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4308
Registered: April 2011
Karma: 0
General (4 Stars)
I'll try that head and arm bone difference method, otherwise i'll leave it alone as it isn't that important. I'm also manually setting the camera every 0.1 seconds, is there any way to do this smoother? I've thought about setting the camera in the OnThink() hook but i'm not sure if that makes stuff smoother.

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: Issue with converting a facing to a Vector3.Z value to look at [message #464487 is a reply to message #464420] Fri, 16 March 2012 09:07 Go to previous messageGo to next message
jonwil is currently offline  jonwil
Messages: 3557
Registered: February 2003
Karma: 0
General (3 Stars)

I dont know of any better way to force the camera to follow a player, nor do I know of any better way to detect the tilt.


Jonathan Wilson aka Jonwil
Creator and Lead Coder of the Custom scripts.dll
Renegade Engine Guru
Creator and Lead Coder of TT.DLL
Official member of Tiberian Technologies
Re: Issue with converting a facing to a Vector3.Z value to look at [message #464488 is a reply to message #464420] Fri, 16 March 2012 09:21 Go to previous message
iRANian is currently offline  iRANian
Messages: 4308
Registered: April 2011
Karma: 0
General (4 Stars)
Thanks, I'll guess I'll just have to try out those methods and see what the results are.

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Previous Topic: just wondering : weaponbagclass
Next Topic: ssgm wont load custom objects.gm
Goto Forum:
  


Current Time: Thu Nov 21 16:47:41 MST 2024

Total time taken to generate the page: 0.00621 seconds