Skrakle Posted May 16, 2015 Posted May 16, 2015 I'm setting my camera based on my model's position/rotation but i'd like the camera to be positioned a little further back so i can actually see the model move, i think what i'm looking for is something like vector forward. Right now, i'm setting it at the exact same x/z coordinates. Vec3 pos = player_entity->model->GetPosition(); camera->SetPosition(Vec3(pos.x, pos.y + 2, pos.z)); What would be required to re-calculate the new x/z coordinates of the camera? Quote
gamecreator Posted May 16, 2015 Posted May 16, 2015 Have you tried using move? I think that can move an entity (like a camera) on its own axis. 1 Quote
YouGroove Posted May 16, 2015 Posted May 16, 2015 Some TPS working camera example for you. Remove all uneeded code import "Scripts/AnimationManager.lua" Script.Camera = "" --entity Script.teamid=1 function Script:Start() --self.btnExit = Button:Create("Exit", 0, 0, 100, 50, self, self.btnExit_Click) self.playerMovement = Vec3(0,0,0) self.cameraYaw = 0 self.cameraPitch = 10 self.dx = 0 self.dy = 0 self.mousePos = 100 self.trapMode = false self.stars = 0 self.shooting = false self.moveSpeed = 10 self.fireRate = 500 self.lastFireRate = 0 self.alive = true self.dyingAnimationComplete = false -- 2 "layers" of animations. the base layer and the upper body layer self.baseAnimMgr = AnimationManager:Create(self.entity) self.entity:SetKeyValue("type", "player") self.state="idle" self.attackName="" self.pick = PickInfo() self.entity:SetPickMode(0,true) end function Script:UpdateWorld() if self.alive == false then return end self.entity:SetRotation(0,180,0,true) self:Movement() self:CameraRotation() self:Animations() end function Script:attackEnd() self.state="idle" end function Script:CameraRotation() -- rotate yaw and tell the player about it so the character can use it in SetInput() local mpos = App.window:GetMousePosition() self.dx = Math:Curve((mpos.x - self.mousePos) / 10.0, self.dx, 3.0 / Time:GetSpeed()) self.cameraYaw = self.cameraYaw + self.dx -- rotate pitch self.dy = Math:Curve((mpos.y - self.mousePos) / 10.0, self.dy, 3.0 / Time:GetSpeed()) local pitch = self.cameraPitch + self.dy if pitch > -25 and pitch < 55 then self.cameraPitch = pitch end -- reset the mouse position App.window:SetMousePosition(self.mousePos, self.mousePos) end function Script:Movement() -- handle player movement self.playerMovement.z = ((App.window:KeyDown(Key.W) and 1 or 0) - (App.window:KeyDown(Key.S)and 1 or 0)) * Time:GetSpeed() * self.moveSpeed --self.playerMovement.x = ((App.window:KeyDown(Key.D) and 1 or 0) - (App.window:KeyDown(Key.A)and 1 or 0)) * Time:GetSpeed() * self.moveSpeed if self.state=="attack" then self.playerMovement.z=0 end -- reduce speed when moving backwards --if self.playerMovement.z < 0 then --self.playerMovement.z = self.playerMovement.z --end if self.playerMovement.z > 0 and self.state~="attack" then self.state="walk" end if self.playerMovement.z == 0 and self.state~="attack" then self.state="idle" end -- move the camera to the player and set the yaw from 3rd person view self.Camera:SetPosition(self.entity:GetPosition(true), true) self.Camera:SetRotation(Vec3(self.cameraPitch, self.cameraYaw, 0), true) -- offset the camera up and back self.Camera:Move(0, 5, -15) -- rotate the model along with the camera self.entity:SetRotation(Vec3(0, self.cameraYaw +180, 0)) -- move the controller in the rotation of the player self.entity:SetInput(self.cameraYaw, self.playerMovement.z, 0 --[[self.playerMovement.x]], 0, false, 1) if App.window:MouseHit(1) and self.state~="attack" then self.state="attack" self.baseAnimMgr:SetAnimationSequence("attack", 0.01, 50,1,self,self.attackEnd) end end function Script:Animations() -- consider base animations here if self.state=="idle" and self.state~="attack" then self.baseAnimMgr:SetAnimationSequence("idle", 0.005, 200) end if self.state=="walk" and self.state~="attack" then self.baseAnimMgr:SetAnimationSequence("walk", 0.01, 200) end end function Script:UpdatePhysics() end function Script:Draw() -- the order we put these in matters! self.baseAnimMgr:Update() end function Script:PostRender(context) end function Script:Delete() end 2 Quote Stop toying and make games
Skrakle Posted May 16, 2015 Author Posted May 16, 2015 Thanks guys, camera:move worked as suggested! Quote
karmacomposer Posted June 29, 2017 Posted June 29, 2017 import "Scripts/AnimationManager.lua" How to make this work with the current version of Leadwerks? In the current version, I cannot find a lua script called AnimationManager. ?? Mike Quote MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 980 GTX with 16gb vram / SSD drives MSI Dominator Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1060 GTX with 8gb vram / SSD drives Alienware Laptop - Core i7 - 8 cores / 3ghz / 32gb RAM / Nvidia 1070 Ti with 16gb vram / SSD drives My Patreon page: https://www.patreon.com/michaelfelkercomposer My music for sale: https://www.tgcstore.net/category/513?format=all&perpage=30&textures=undefined&price=all&order=default&artists[]=87213 Custom synths and sounds - http://www.supersynths.com
Recommended Posts
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.