Thanks.
I would like to see an example of inputs from the keyboard rotating an object. So the player presses a key and the object rotates left, right, up, down and so on.
Hi BigDaz. This is very easy to do.
First, you must set a new action and KeyMap a key for this action. Edit the "input.cfg" file (GameEditor -> Items (right panel) -> Config -> input.cfg. They will be open in the Script editor. Add the lines that are in bold. You can change KeyR for any Key that you want. Also you can set any name for the Action.
###########################################################################
# input settings for specific controllers
InputSet Player Camera
...
InputSet Player Character
Action Forward
Action Backward
Action Left
Action Right
Action Fire
Action Jump
Action MouseJump
Action Run
Action WeaponA
Action WeaponB
Action RotateObject
KeyMapping KeyUp Forward
KeyMapping KeyDown Backward
...
KeyMapping Joy2 Jump
KeyMapping Joy3 Run
KeyMapping KeyR RotateObject
...
Now, open the Rotating Object OPR file and add the input area.
ControllerInputCenter 0 0 0
ControllerInputBoxSize 3 3 3
This will set a Box Input Area (size 3x3x3) centered at the center of the Object. To help you to adjust the size and the center of the Input Box you can turn on "Show Input Areas" in the GameEditor. Options -> Show Iput Areas (check it

).
Now, go to edit the script file.
First add a global script variable. This variable will be true if the player is rotating the object. False if not.
// variables
bool inputRotating = false;
In the DynamicsAdvance function only rotate the object if the inputRotating variable is true.
void DynamicsAdvance( Object@ object, float seconds)
{
if(inputRotating)
{
// Roate the Object here.
// .....
}
}
Now, add the HandleEvent function (see the complete script code).
The complete script:
/*
Controller Settings:
RotateXAxis - Angle to rotate, in a second, along the X Axis.
RotateYAxis - Angle to rotate, in a second, along the Y Axis.
RotateZAxis - Angle to rotate, in a second, along the Z Axis.
*/
// constants (modifiable from controller settings, see Initialize function)
float ROTATE_X_AXIS = 0;
float ROTATE_Y_AXIS = 90;
float ROTATE_Z_AXIS = 0;
// variables
bool inputRotating = false;
//------------------------------------------------------------
//
// void Initialize( Object@ object)
//
// This function is called when the controller is created.
// Any initialization should be done here.
//
// Parameters:
//
// object - The object that this controller is to act upon.
//
void Initialize( Object@ object)
{
// Get the Controller Settings front the Object Properties.
ROTATE_X_AXIS = object.GetControllerSettingFloat( "RotateXAxis", ROTATE_X_AXIS);
ROTATE_Y_AXIS = object.GetControllerSettingFloat( "RotateYAxis", ROTATE_Y_AXIS);
ROTATE_Z_AXIS = object.GetControllerSettingFloat( "RotateZAxis", ROTATE_Z_AXIS);
}
//------------------------------------------------------------
//
// bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
//
// All of the keys that can be pressed for this object are
// passed to this function every frame.
//
// Parameters:
//
// object - The object that this controller is to act upon.
//
// event - Name of the event type
//
// params - Parameters for the event (specific to each event type)
//
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{
// Only Events for Player.
if (params.player == null)
return false;
// Input event
if (event == "Input")
{
if (params.stringValue == "RotateObject")
{
if(params.floatValue >= 0.5f)
{
inputRotating = true;
return true;
}
}
}
return false;
}
//------------------------------------------------------------
//
// void DynamicsAdvance( Object@ object, float seconds)
//
// This function is called once per dynamics step. Any
// object movement should be done here.
//
// Parameters:
//
// object - The object that this controller is to act upon.
//
// seconds - How much time has passed since last call.
//
void DynamicsAdvance( Object@ object, float seconds)
{
if(inputRotating)
{
// Get the Current Matrix of the Object.
Matrix mtx = object.GetCurMatrix();
// ROTATE along Axis.
// X Axis Rotation.
if( ROTATE_X_AXIS != 0 )
{
mtx.RotateAxis( Vector(1, 0, 0), ROTATE_X_AXIS * seconds);
} // End X Axis Rotation.
// Y Axis Rotation.
if( ROTATE_Y_AXIS != 0 )
{
mtx.RotateAxis( Vector(0, 1, 0), ROTATE_Y_AXIS * seconds);
} // End Y Axis Rotation.
// Z Axis Rotation.
if( ROTATE_Z_AXIS != 0 )
{
mtx.RotateAxis( Vector(0, 0, 1), ROTATE_Z_AXIS * seconds);
} // End Z Axis Rotation.
// End ROTATE.
// Set the Matrix to the Object.
object.GetCurMatrix().XAxis = mtx.XAxis;
object.GetCurMatrix().YAxis = mtx.YAxis;
object.GetCurMatrix().ZAxis = mtx.ZAxis;
// The User must hold the Key to continue rotating the object.
inputRotating = false;
}
}
Hope help you.