YouGroove Posted March 3, 2013 Share Posted March 3, 2013 ******************************** A camera that will follow the entity that is moving in the X axis : ********************************** 1) in App.lua declare the global camera entity : function App:Start() ... --Create a world f.world=World:Create() ... camera = Camera:Create() camera:SetRotation(35,0,0) camera:Move(0,0,-30) ... return true end 2) in the character AI lua script in the updatePhysics loop just add these lines : function Script:UpdatePhysics() local time=Time:GetCurrent() self.entity:GoToPoint(20,0,-15,1.4,1); xpos=self.entity:GetPosition().x camera:SetPosition(xpos,10,-30) self.entity.animationmanager:SetAnimationSequence(self.sequence.walk,0.04,200) end ****************** How it works : We get position in X axes of the character that is moving by calling : xpos=self.entity:GetPosition().x Then we change camera position in X axis with the value of the character in X axis : camera:SetPosition(xpos,10,-30) So the camera will follow the character in the X axis as it moves. You can extend the script and do the same with Z value or Y if the character would climb some stairs. 1 Quote Stop toying and make games 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.