SetInput
This functions set the movement parameters of an entity that uses the CharacterPhysics physics mode.
When an entity uses character physics, the physics will control the object's rotation, and calls to Entity::SetRotation() and similar functions will have no effect.
Syntax
- void SetInput(float angle, float move, float strafe=0, float jump=0, const bool crouch = false, const float maxaccel = 1, const float maxdecel = 0.5, const bool detailed = false, const float maxrotationspeed=5.0)
Parameters
- angle: the angle the character faces.
- move: the forward movement of the character.
- strafe: the horizontal movement of the character.
- jump: the jumping force to apply.
- crouch: set to true for crouching mode (included for future development)
- maxacceleration: the maximum acceleration the character may use to speed up.
- maxdecelleration: the maximum acceleration the character may use to slow down.
- detailed: set this to true for characters that have a camera mounted on them. This will provide more accurate physics, but will also be more expensive to calculate.
- maxrotationspeed: this is the maximum speed the entity can turn, in degrees per physics step.
Remarks
The input values should not be modulated by the application speed. The physics system will automatically adjust motion according to the framerate.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Entity* player = NULL;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
World* world = World::Create();
Camera* camera = Camera::Create();
camera->SetRotation(35, 0, 0);
camera->Move(0, 0, -8);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create the ground
Model* ground = Model::Box(10, 1, 10);
ground->SetPosition(0, -0.5, 0);
ground->SetColor(0.0, 1.0, 0.0);
//Create a shape
Shape* shape = Shape::Box(0, 0, 0, 0, 0, 0, 10, 1, 10);
ground->SetShape(shape);
shape->Release();
//Create a character
player = Pivot::Create();
Entity* visiblecapsule = Model::Cylinder(16, player);
visiblecapsule->SetScale(1, 2, 1);
visiblecapsule->SetPosition(0, 1, 0);
player->SetMass(1);
player->SetPhysicsMode(Entity::CharacterPhysics);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
float move = (window->KeyDown(Key::Up) - window->KeyDown(Key::Down)) * 4;
float strafe = (window->KeyDown(Key::Right) - window->KeyDown(Key::Left)) * 4;
player->SetInput(0, move, strafe);
world->Update();
world->Render();
context->Sync();
}
return 0;
}