Jump to content

Recommended Posts

Posted

Hi everyone,

 

Here is my custom FPS player concept with leaning ability (Figure 1)

This concept includes 1 camera, 2 boxes (box1 and box2), very simple

 

Expected:

  • I can control the camera by mouselook script - DONE (It is easy)
  • Box1:SetCollisionType(Collision.Character)
  • Box1:SetPhysicsMode(Entity.CharacterPhysics)
  • Assign WDAS control to Box1, Box1 can turn on Y Axis, following camera rotation - DONE (It is easy too, using Entity:SetInput() in Script:UpdateWorld())
  • camera:SetParent(box2) so that when box 2 rotates, camera will be rotated too (Figure 2)
  • Press Q/E to rotate (Entity:Turn) box 2 on Z Axis

Problem:

  • Leaning is ok when I don't change camera rotation, just leave the mouse there and press Q or E, my camera will move well, the result is I can peek out the wall.
  • When I move mouse to look around, Box1 (player base)'s direction changes too, but Box2 is standing still. the result is I can't lean as the right way (Figure 3)

My failed solutions:

  • Solution1: Using Box2:SetRotation(camera:GetRotation(true)) in Script:UpdateWorld(), this can make Box2 rotate as camera's rotation, but I can't use Q or E to turn Box2 anymore. Just because its Z axis was "locked" by Entity:SetRotation()
  • Solution2: Create a local Target = Model:Box() and place right on the line of sight from camera, so that when camera turn around, Target will move too, then use Box2:Pick(Target,2) to align Box2's Z axis with a hope that I can use Q or E again but no help, it was locked too by Entity:Pick()
  • Solution3: Using Box2:AlignToVector() but it acts so weird, I can't use Q or E too.

Finally, I think I need my Box2 can be rotated only on Y axis (follow camera rotation in global) but Z axiz is still free to be turned

 

Any idea for my concept ? Please show me a better one or give me some advices to use a right function, I will appreciate smile.png

post-16833-0-54254600-1457147650_thumb.jpg

Posted (edited)

If you want something like call of duty.

 

if (window->KeyDown(Key::Q)){

Vec3 angle = camera->GetRotation();

Vec3 pos = camera->GetPosition();

if ( angle.z > -15){ // it will only lean 15 degrees left or right

angle.z -= 1.5; // rotates the camera a bit to the left

pos.x -= 0.5; // moves the camera a bit to the left

pos.y -= 0.5; // moves the camera a bit down

camera->SetPosition(pos);

camera->SetRotation(pos);

}

}

 

if (window->KeyDown(Key::E)){

Vec3 angle = camera->GetRotation();

Vec3 pos = camera->GetPosition();

if ( angle.z < 15){

angle.z += 1.5; // rotates the camera a bit to the right

pos.x += 0.5; // moves the camera a bit to the right

pos.y -= 0.5; // moves the camera a bit down

camera->SetPosition(pos);

camera->SetRotation(pos);

}

}

 

I don't actually have access to a computer with LE installed, but it should be something like that.

 

edit; Ok, now I read "Lua" in the title. I didn't use it, so I can't really help, but this page could help:

http://www.leadwerks.com/werkspace/page/api-reference/_/entity/entitysetrotation-r30

Edited by Undac
  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...