Game Development Community

how constrain pitch function angle?

by Tsai Ming Hung · in Torque 3D Professional · 11/25/2011 (11:49 pm) · 11 replies

I use yaw and pitch by mouse,but I want to constrain the pitch function angle, don't let camera down in player character bottom .so please ask every senior can take my problem,thanks.

#1
11/26/2011 (4:57 am)
is anyone can give me direction or method?
#2
11/27/2011 (6:02 pm)
I'm not exactly sure what you are asking, but if you want to restrict the angle that a player can look up and down, there are minLookAngle and maxLookAngle variables in the PlayerData datablock that you can change.
#3
11/27/2011 (9:51 pm)
sorry,my English is pool!I want to know how to set pitch function limit,just pitch not yaw,thanks.
My camera is set
%client.camera.setOrbitObject(%client.player,%client.camera.getRotation() ,0.0,5.0,%dist,true);
so I use pitch and yaw function to move the camera,but I want constrain pitch angle.
#4
11/28/2011 (3:27 am)
If you want to control pitch (as in up and down) then (just as A F said) change minLookAngle and maxLookAngle.

Hit "F6" to bring up the datablock editor.
Find "PlayerData"
And change minLookAngle and maxLookAngle in "DefaultPlayerData->Camera" (or whatever player name is relevant to you in there)

If you don't want to change it there, I believe you will find what you need in the 'player.cpp' file. But that will require some digging around on your part ;)

Good luck.
#5
11/28/2011 (5:45 am)
I already try Micheal's suggestion,but it doesn't work,I guess the reason is use setOrbitObkect camera,so minLookAngle and maxLookAngle doesn't work,how can I in default.bind.cs to get camera.getRotation function?If I can get this parameter of function,it should add angle to decide pitch is allow or stop.thanks your replies.
#6
11/28/2011 (5:51 am)
Hmm, question:

Are you trying to stop the player from moving the camera angle up and down, and keep it locked at an angle of your choice?
#7
11/28/2011 (6:10 am)
locked at an angle?sorry,I don't understand,post my code to show you

<code>
function onRightMouseLook(%val) {
if (%val) {
hideCursor();
moveMap.bind(mouse,xaxis,yaw);
//moveMap.bind(mouse,yaxis,pitch);
} else {
showCursor();
}
}
globalActionMap.bind( mouse, button1, onRightMouseLook );
</code>


how can I modify under code to constrain angle degree
<code>
function pitch(%val)
{
%pitchAdj = getMouseAdjustAmount(%val);
if(ServerConnection.isControlObjectRotDampedCamera())
{
// Clamp and scale
%pitchAdj = mClamp(%pitchAdj, -m2Pi()+0.01, m2Pi()-0.01);
%pitchAdj *= 0.5;
}

$mvPitch += %pitchAdj;
}
</code>

#8
11/28/2011 (1:24 pm)
I think Tsai is trying to control the camera, not the player.

@Tsai,
I think you will want to bind the mouse motion to a function rather than the xaxis. Then the function can take input from the mouse and convert to a pitch value for the camera. Then the function can update the position or angles of the camera. If you are bound right to the mouse control there is no way to filter the motion.

Does this make sense?
#9
11/28/2011 (7:15 pm)
yes,thanks Frank,can you give me some idea or demo to modify the picth code?because I search many info but didn't know how to implement my idea,thanks.I use orbitObject mode.
#10
11/29/2011 (12:23 am)
Use this to bind a command to an event like mouse or joystick:
moveMap.bindCmd

Go here tdn.garagegames.com/wiki/Script/Input_Keys_and_Maps. This should help cover the bind information.

Go here for more depth on bind commands:
tdn.garagegames.com/wiki/Torque_Console_Objects#ActionMap

Now you should be able to use the movemap.bindcmd to bind a command to your mouse movement. Then you need to determine how to modify the camera object. I am not sure how to do that part.

Edit:
Oh wait, check out the orbitmode settings here:
tdn.garagegames.com/wiki/Torque_Console_Objects_2#Camera

You may have to do some matrix math to limit the camera rotations.
#11
11/29/2011 (1:16 am)
thanks Frank,you are so considerate,I will try.^^Thanks again.