Jump to content

LE 3 LITTLE CODE EXAMPLES :


YouGroove
 Share

Recommended Posts

********************************

 

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.

  • Upvote 1

Stop toying and make games

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...