Merries Posted July 3, 2016 Share Posted July 3, 2016 I have done quite a bit of snooping about, on the forums and going through the tutorials on YouTube, the complete series done by Jorn Theunisen is old and I understand some parts are outdated. Keeping in mind I'm not a programmer though I can read it fairly well just cannot write it, has anyone developed a rpg style 3rd person camera script? Not sure what I'm referring to a example is, Skyrim or even WOW, where the camera follows and has collision detection so it does not drift through walls, and you can rotate around it with the right mouse button. I'm sure there are developers out there who know exactly what type of setup I'm referring to Any help would be appreciated. Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
Genebris Posted July 3, 2016 Share Posted July 3, 2016 Place a pivot inside player, parent camera to this pivot, rotate this pivot depending on mouse coordinates. To avoid walls throw a raycast from this pivot to the camera, if it hits something in between then position the camera in hit position. Quote Link to comment Share on other sites More sharing options...
Thirsty Panther Posted July 3, 2016 Share Posted July 3, 2016 I thought there was one on the Workshop but I cant find it. Found YouGrooves script. Its a couple of years old but should get you started. http://www.leadwerks.com/werkspace/page/tutorials_legacy/_/artwork/third-person-template-r114 1 Quote Link to comment Share on other sites More sharing options...
Merries Posted July 3, 2016 Author Share Posted July 3, 2016 Thanks all, Genebris just got started yesterday, understood what you said but it went right over my head *laughs* I'm sure Ill figure that out now I know how its done. Thanks Panther, love the name btw. Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
Elyzera Posted July 5, 2016 Share Posted July 5, 2016 omg thanks you! im only remove App. in windows and all fine Quote Link to comment Share on other sites More sharing options...
Merries Posted July 5, 2016 Author Share Posted July 5, 2016 Ok folks please one of you excellent programmers out there give this poor lady a hand, I have looked at the script for the Ball tutorial, I have watched some videos on the controllers, I have looked at the FPS script. I have done the official tutorials and I'm stuck. Would someone kindly make a 3rd party camera? I do wish to learn LUA, but I need to start smaller then a camera controller Im pretty sure, thank you!! Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
Genebris Posted July 5, 2016 Share Posted July 5, 2016 That's actually a very basic task so you should do it yourself. Take FPS script, find a line where it creates a camera and replace camera creation with pivot creation (Camera:Create -> Pivot:Create). Then right after this create an actual camera, parent it to this pivot and offset by -1 meter on Z in local coordinates. You will probably want to remove a part of code that makes FPS player model invisible because you actually want to see it from this perspective. It's somewhere in Start(). Or just attach any other model to the player. Quote Link to comment Share on other sites More sharing options...
Merries Posted July 5, 2016 Author Share Posted July 5, 2016 Genebris what about all the rest of the code? What can you delete? What do you comment out? How do you attach it to a player? How do you determine distance between the player and the camera and the camera height? Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
Merries Posted July 5, 2016 Author Share Posted July 5, 2016 I thought there was one on the Workshop but I cant find it. Found YouGrooves script. Its a couple of years old but should get you started. http://www.leadwerks.com/werkspace/page/tutorials_legacy/_/artwork/third-person-template-r114 Sadly the above script ran as instructed could not get it to work, I could detail out the errors but it would come down to someone walking me through replacing code as needed, again I can mod but ask me to code how to make a cup of tea I cannot connect the dots, believe me I have tried for over 2 years..the classes I took are all 'This is a function, this is a loop' but don't teach you how to use it in a practical manner. Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
Genebris Posted July 5, 2016 Share Posted July 5, 2016 Genebris what about all the rest of the code? What can you delete? What do you comment out? How do you attach it to a player? Leave the rest of the code untouched. use default FPS prefab. How do you determine distance between the player and the camera and the camera height? When camera is attached to it's pivot set camera position to 0,1,-1 in local space. It will be offset by 1 meter behind player and one meter above player. Quote Link to comment Share on other sites More sharing options...
Merries Posted July 5, 2016 Author Share Posted July 5, 2016 I appreciate your help, I honestly do, but what do you mean leave the FPS prefab? That's an actual model, will that be walking around behind your character though it's invisible won't that interfere with collisions etc? Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
Genebris Posted July 5, 2016 Share Posted July 5, 2016 Replace your fps script with this FPSPlayer.lua Quote Link to comment Share on other sites More sharing options...
Merries Posted July 5, 2016 Author Share Posted July 5, 2016 Last question how do I attach that to the player will there be a field exposed to do so? Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
Elyzera Posted July 6, 2016 Share Posted July 6, 2016 Last question how do I attach that to the player will there be a field exposed to do so? 3rdPerson.lua Script.Camera = nil --entity Script.positionDifference = Vec2(0,0) Script.picksphere = Model:Sphere() function Script:Start() self.playerMovement = Vec3(0,0,0) self.cameraYaw = 0 self.cameraPitch = 10 self.dx = 0 self.dy = 0 self.mousePos = 100 self.moveSpeed = 10 self.entity:SetKeyValue("type", "player") -- HUD stuff self.crosshairs = Texture:Load("Materials/HUD/crosshair.tex") self.entity:SetFriction(0,0) local material = Material:Create() material:SetBlendMode(5)--Blend.Invisible self.entity:SetMaterial(material) material:Release() self.entity:SetShadowMode(0) self.picksphere:SetColor(1.0,0.0,0.0) self.picksphere:SetPickMode(0) end function Script:UpdateWorld() end function Script:CameraRotation() -- rotate yaw and tell the player about it so the character can use it in SetInput() local mpos = 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 window:SetMousePosition(self.mousePos, self.mousePos) end function Script:Movement() -- handle player movement self.playerMovement.z = ((window:KeyDown(Key.W) and 1 or 0) - (window:KeyDown(Key.S)and 1 or 0)) * Time:GetSpeed() * self.moveSpeed self.playerMovement.x = ((window:KeyDown(Key.D) and 1 or 0) - (window:KeyDown(Key.A)and 1 or 0)) * Time:GetSpeed() * self.moveSpeed -- reduce speed when moving backwards if self.playerMovement.z < 0 then self.playerMovement.z = self.playerMovement.z * .50 end local positionPlayer = self.entity:GetPosition(false) self.positionDifference.y = Math:Curve(positionPlayer.y ,self.positionDifference.y,3) -- 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, 3, -4) -- rotate the model along with the camera self.entity:SetRotation(Vec3(0, self.cameraYaw, 0)) -- move the controller in the rotation of the player self.entity:SetInput(self.cameraYaw, self.playerMovement.z,self.playerMovement.x , 0, false, 1) end function Script:Fire() -- hide ourselves do we don't accidently pick ourselves self.entity:Hide() local p = PickInfo() local c = Vec2(0) c.x = window:GetWidth() / 2 c.y = window:GetHeight() / 2 if self.Camera:Pick(c.x, c.y, p) then if p.entity ~= nil then self.picksphere:SetPosition(p.position,false) end end self.entity:Show() end function Script:UpdatePhysics() self:Movement() self:CameraRotation() if window:MouseDown(1) == true then self:Fire() end end function Script:PostRender(context) local width = window:GetWidth() local height = window:GetHeight() local w = self.crosshairs:GetWidth() local h = self.crosshairs:GetHeight() local pos = Vec2(0) pos.x = (width / 2) - (w / 2) pos.y = (height / 2) - (h / 2) context:SetBlendMode(Blend.Alpha) context:DrawImage(self.crosshairs, pos.x, pos.y) context:DrawText("Mouse button Left to fire", 10, 70) context:DrawText("W/S to walk forward / backward", 10, 90) context:DrawText("A/D to strafe", 10, 110) context:SetBlendMode(Blend.Solid) end 1 Quote Link to comment Share on other sites More sharing options...
Merries Posted July 6, 2016 Author Share Posted July 6, 2016 After sleeping on it I came to realize something. As I'm use to Unity every object is a separate game objects so each object has its own script. What I'm seeing here is that scripts may have (for example) camera control built in to the player movement script, so that was throwing me off. Again a big thank you all for helping get on the right course and showing me the code. As I learn I will be documenting and offering it to the community. Quote 3D Game Asset Artist Link to comment Share on other sites More sharing options...
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.