| Blockland Forums > Modification Help |
| Setting an object directly right of a player |
| (1/2) > >> |
| elm:
No matter how the player turns, it'll stay to it's right. I need the equation because I am bad at math, so can anyone tell me how I would do this? thanks. |
| Space Guy:
%player.getForwardVector() returns a length 1 vector along the XY axis in the direction the player is facing. %player.getEyeVector() returns a length 1 vector in the direction their head is facing. (including looking up, to the side if they use free-look) |
| Treynolds416:
Here you go: --- Code: ---function getDirectRightPoint(%player,%mag) { %curAim = %player.getEyeVector(); %curX = getWord(%curAim,0); %curY = getWord(%curAim,1); %curZ = getWord(%curAim,2); %theta = mRadToDeg(mATan(%curY,%curX)); if(%curX > 0 && %curY > 0) %angle = %theta; else if(%curX < 0 && %curY > 0) %angle = 180 - %theta; else if(%curX < 0 && %curY < 0) %angle = %theta + 180; else if(%curX > 0 && %curY < 0) %angle = 360 - %theta; else if(%curX == 0) { if(%curY > 0) %angle = 180; else if(%curY < 0) %angle = 360; else return false; } else if(%curY == 0) { if(%curX > 0) %angle = 90; else if(%curX < 0) %angle = 270; else return false; } %rAngle = %angle - 90; if(%rAngle < 0) %rAngle += 360; %rightPos = %mag * mCos(%rAngle) SPC %mag * mSin(%rAngle) SPC %curZ; return vectorAdd(%rightPos,%player.getPosition()); } --- End code --- This code returns a point at a ninety degree angle to where the player is currently looking, presumably to place a brick. By "directly right" I assumed you meant a right angle. The arguments are %player for the player object and %mag, for the distance from the player the object will be. Important: This code has the point placed at the same height as before. This won't be a problem unless the object you are talking about is way above the player. The object will be at 90 degrees on the XY plane, but when the player leans back they can see the object in periphiral vision. If this is the case, I'll need to append some stuff to the code, but the situation would technically become a bit more complicated than just "to the right of". |
| elm:
Lol thanks, I should of paid attention more in my math classes... |
| Space Guy:
Oh, I misunderstood the question. The cross product of two vectors is one perpendicular to both, so that of the forward vector and 0 0 1 would be to one side of the player - I don't know which side but should be the same right/left hand each time and easier than the trigonometry. vectorCross("0 1 0","0 0 1") = "1 0 0" (+Y and +Z -> +X) vectorCross("1 0 0","0 0 1") = "0 -1 0" (+X and +Z -> -Y) vectorCross("0 0 1","0 1 0") = "-1 0 0" (if you wanted to generate the opposite hand direction, swap the arguments or scale the vector by -1) |
| Navigation |
| Message Index |
| Next page |