GetVelocity
This function gets entity's velocity, in global or local space.
Syntax
- Vec3 GetVelocity(bool global = true)
Parameters
- global: if set to true the velocity is returned in global space (relative to the world), otherwise it is returned in local space (relative to the entity).
Returns
Returns the entity velocity.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
Entity* entity = 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(15, 0, 0);
camera->Move(0, 0, -8);
Light* light = DirectionalLight::Create();
light->SetRotation(35, 35, 0);
//Create the ground
Model* ground = Model::Box(10, 0.1, 10);
ground->SetColor(0.0, 1.0, 0.0);
//Create a shape
Shape* shape = Shape::Box(0, 0, 0, 0, 0, 0, 10, 0.1, 10);
ground->SetShape(shape);
shape->Release();
//Create a model
entity = Model::Box();
entity->SetColor(0.0, 0.0, 1.0);
entity->SetPosition(0, 5, 0);
entity->SetMass(1);
//Create a shape
shape = Shape::Box();
entity->SetShape(shape);
shape->Release();
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
world->Update();
world->Render();
context->SetBlendMode(Blend::Alpha);
context->DrawText("Velocity: " + entity->GetVelocity().ToString(), 2, 2);
context->Sync();
}
return 0;
}