Author Topic: Alternative to getEyeVector(); that ignores freelooking?  (Read 1574 times)

Alright, so I have this function here by port.
Code: [Select]
function Player::getLOSPoint(%this, %mask, %dist)
{
%eyePoint = %this.getEyePoint();
%eyeVector = %this.getEyeVector();
%endPoint = vectorAdd(%eyePoint, vectorScale(%eyeVector, %dist));
%ray = containerRayCast(%eyePoint, %endPoint, %mask, %this);

if (%ray)
{
return getWords(%ray, 1, 3);
}

return %endPoint;
}
It works just dandy, but the problem is that getEyeVector(); takes freelooking into account as well, so if I use this for weapons I could just hold freelook and fire backwards.
Is there any alternative to getEyeVector(); that ignores freelook?
By the way, before you ask, I did try getWords(getForwardVector(), 0, 1) SPC getWord(getEyeVector(), 2); but for some dumb ass reason getForwardVector can't go below or above a certain angle.

Well, you could probably do something like this:

Code: [Select]
%vector = getWords(%player.getForwardVector(),0,1) SPC getWord(%player.getEyeVector(),2);

That SHOULD get you the x/y of forwardVector (direction they are facing regardless of freelook) and the Z of their eye (which is unaffected by freelook)

Well, you could probably do something like this:

Code: [Select]
%vector = getWords(%player.getForwardVector(),0,1) SPC getWord(%player.getEyeVector(),2);

That SHOULD get you the x/y of forwardVector (direction they are facing regardless of freelook) and the Z of their eye (which is unaffected by freelook)
By the way, before you ask, I did try getWords(getForwardVector(), 0, 1) SPC getWord(getEyeVector(), 2); but for some dumb ass reason getForwardVector can't go below or above a certain angle.

Above and below are relative terms of Z axis, and we're grabbing only the X and Y axis from getForwardVector. I don't understand what you're trying to say.

Anyway, to more directly answer your question: getMuzzleVector(0) works.

Well, I should probably post the code snipped I have in my WeaponImage::OnFire.
Maybe that'll help figure out why does the angle snap happen.
Code: [Select]
%losPoint = %obj.getLOSPoint(%mask, %this.raycastRange);

%basePoint = %obj.getMuzzlePoint(%slot);
%baseVector = vectorNormalize(vectorSub(%losPoint, %basePoint));

That code is irrelevant, it's just the ::getLOSPoint from my raycasting weapons that actually matters in this case.

Again, Player::getMuzzleVector( 0 ) works just fine for getting where somebody is looking minus freelook. Does it still snap when you use that?

isn't getMuzzleVector affected by the weapon your holding and takes the weapon bobbing into factor?

Well, first off it appears that he's making a custom weapon so he could just make it so there's no muzzle offset. And no, the muzzle point is affected by weapon bobbing. But secondly, calling getMuzzlePoint on a slot that doesn't have a weapon on it produces the same exact result as getEyeVector when freelook is not being used.

Using it for ::getLOSPoint would pretty much be beside the point since it would just fire along the muzzle vector always.

His version of getLOSPoint appears to use getEyeVector instead of getMuzzleVector.

Currently, his issue is trying to get ::getForwardVector() with Z rotation included.
Just changing the third word doesn't work, as it adds them (i.e. looking straight up would give a diagonal such as 0 1 1).

So Port came up with this code, but the problem is that Z is kind of inaccurate. When you look diagonally up, it doesn't shoot directly at the cursor but instead slightly above or something.
Code: [Select]
function Player::getLOSPoint(%this, %mask, %dist)
{
%start = %this.getEyePoint();
%forward = %this.getForwardVector();
 
%z = getWord(%this.getEyeVector(), 2);
 
%xyScale = 1 - mAbs(%z);
%xyScale = mSin(%xyScale * ($pi / 2));
 
%vector = vectorScale(%forward, %xyScale);
%vector = setWord(%vector, 2, %z);
 
%end = vectorAdd(%start, vectorScale(%vector, %dist));
%ray = containerRayCast(%start, %end, %mask, %this);
 
if (%ray)
{
return getWords(%ray, 1, 3);
}
 
return %end;
}

Before anyone mentions that: Tried without a mSin scale too.