Allright, can someone tell what am i doing wrong here is a part of my code:
//Load a prefab
Entity* player = Prefab::Load("Prefabs/player.pfb");
player->SetPosition(0, 6, 0);
player->SetSweptCollisionMode(true);
Camera* camera = Camera::Create(player);
camera->SetPosition(0, 2, 0);
float playerheight;
window->HideMouse();
float walk;
float turn;
float jump;
float jumpspeed = 8;
float speed;
bool cdown = 0;
Vec3 mouse = Vec3(0, 0, 0);
Vec3 velo = Vec3(0, 0, 0);
Vec3 camera_y = Vec3(0, 0, 0);
float mouse_x;
float mouse_y;
float lerp;
while (true)
{
camera->GetPosition();
camera_y = camera->GetPosition();
mouse = window->GetMousePosition();
window->SetMousePosition(window->GetWidth() / 2, window->GetHeight() / 2);
mouse_x += (mouse[0] - window->GetWidth() / 2) / 4.5;
mouse_y += (mouse[1] - window->GetHeight() / 2) / 4.5;
camera->SetRotation(mouse_y, 0, 0);
walk = window->KeyDown(Key::W) *speed - window->KeyDown(Key::S) *speed;
turn = window->KeyDown(Key::D) *speed - window->KeyDown(Key::A) *speed;
speed = 5 + window->KeyDown(Key::Shift) * 2 - window->KeyDown(Key::Control) * 3.5;
lerp = Math::Lerp(2, 0, 0.5);
if (!window->KeyDown(Key::ControlKey) && cdown == 1)
{
cdown = 0;
speed = 8.0;
camera->SetPosition(0, 1.75, 0);
}
if (window->KeyDown(Key::ControlKey) && cdown == 0)
{
cdown = 1;
speed = 4.0;
camera->SetPosition(0, lerp, 0);
}
velo = player->GetVelocity();
if (velo[1] == 0.0)
{
jump = window->KeyHit(Key::Space) * jumpspeed;
}
else
{
jump = window->KeyHit(Key::Space) * 0.0;
}
player->SetInput(mouse_x, walk, turn, jump, cdown, 1, 1, true);
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
Leadwerks::Time::Update();
world->Update();
world->Render();
context->Sync();
}
return 0;
}