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

Parameters

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;
}