Jump to content

Solution for Camera following with SetInput


DudeAwesome
 Share

Recommended Posts

-- MOVEMENT
local move = ((App.window:KeyDown(Key.W) and 1 or 0) - (App.window:KeyDown(Key.S) and 1 or 0))*4
local strafe = ((App.window:KeyDown(Key.D)and 1 or 0) - (App.window:KeyDown(Key.A) and 1 or 0))*4
self.entity:SetInput(0,move,strafe)

-- CAMERA
--self.camera:SetInput(0,move,strafe) //will not work

 

 

i used the code from the docu to create a basic movement script using WASD. SetInput() is available for every Entity that is using the CharacterController. My Problem is that my Camera should move like the character but SetInput will not work for my camera. Any clue how to do this? Using self.camera:Translate() and self.camera.Move() will work but its hard to calculate camera speed from character movement, so my camera is to fast and it will run out. its easier to use my outcommented code line. If I use Character Controller for my camera the game is going crazy.

 

 

I use 3rd person view

It doesn´t work... why? mhmmm It works... why?

Link to comment
Share on other sites

Use the normal entity character controller and set the camera's position (x/z anyway) to the controllers after you call SetInput(). Then take the controllers y position and add an offset because otherwise it'll be at ground level which is probably what you don't want. This is basically what a FPS game does. The player moves around a controller and the camera just gets set to the controllers position with a y offset.

  • Upvote 1
Link to comment
Share on other sites

Video says it's private.

 

I don't think you can. In 3rd person you are generally following something (character). So you still need a character controller. What you do then is set the position to the controllers position, and then use Move() on the camera to offset up back from the character. Then you rotate your camera to look down (or do a point at function to point at the character).

Link to comment
Share on other sites

It is actually very easy.

 

self.entity:SetInput(blah, blah, blah);
self.camera:SetPosition(self.entity:GetPosition())
self.camera:SetRotation(Vec3(45, 0, 0))
self.camera:Move(Vec3(0, 3, 2))

 

Just play around with the Move() values to get the distance right, and the rotation value to get it pointing at the character right. If you want to add rotation around with the mouse it gets a little more involved.

  • Upvote 1
Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...