Jump to content
Chris Vossen

What tutorial would be most useful

Recommended Posts

My list would be small gem tutorials:

  1. Character Controller
  2. Pickups
  3. Projectile Weapons
  4. Melee Weapons
  5. AI

NOTE: I'm heavily biased towards the FPS genre.

Share this post


Link to post

Third Person camera with :

- mouse character orientation

- keys for walk forward / backward

- rocket launcher (creation of the projectile , moving it , and detect collision something collidable)

 

I think we should not include Golbin or ennemy caus it will complicate the code, if the tutorial will contain some weapon , detection against somehting collidable and juts play a sound when hit, will be more simple.

So i would say, no AI states that will make more code and make less clear.

 

For code perhaps several Lua files :

- animations.lua (it would receive only one parameter like "walk", "idle")

- thirdCamera.lua (a real that rotates with the player orientation, not a travelling one)

- launcher.lua (for the weapon code)

Share this post


Link to post

Thanks, it's a start.

I notice that when attached to a camera, it makes the camera slowly but 'continuously' move (when the keys are not pressed).. I tried adding mass to the camera to stop it without success. Any ideas how it can be stabilised?

Share this post


Link to post

Here is the start of a 3rd person camera. I'll write up a blog explaining the code tomorrow:

 

http://www.leadwerks.com/werkspace/files/file/406-3rd-person-camera/

 

For those who don't want to click download you can copy and paste this:

 


Script.target = nil--Entity "Target"

Script.distance = 5--float

Script.debugphysics = false--bool

Script.debugnavigation = false--bool

Script.pitch = 35--float

Script.angle = 180--float

Script.pickradius = 0.5--float

Script.verticaloffset = 1.8--float

Script.smoothness = 30--int

 

function Script:Start()

if self.target==nil then return end

 

--debug functions for viewing physics or navigation in game

self.entity:SetDebugPhysicsMode(self.debugphysics)

self.entity:SetDebugNavigationMode(self.debugnavigation)

 

end

function Script:UpdatePhysics()

 

--Exit the function if the target entity doesn't exist

if self.target==nil then return end

 

local originalcamerapos = self.entity:GetPosition(true)

local targetpos = self.target:GetPosition(true)

local newcamerapos = self.target:GetPosition(true)

targetpos.y = targetpos.y+self.verticaloffset

self.entity:SetPosition(targetpos)

self.entity:SetRotation(self.target:GetRotation(true))

self.entity:Turn(self.pitch,self.angle,0)

self.entity:Move(0,0,-self.distance)

 

local targetpickmode = self.target:GetPickMode()

self.target:SetPickMode(0) --so that the pick doesn't hit the target

newcamerapos = self.entity:GetPosition()

local pickinfo = PickInfo()

if (App.world:Pick(targetpos,self.entity:GetPosition(),pickinfo,self.pickradius,true)) then

newcamerapos = pickinfo.position

end

newcamerapos.x = Math:Curve(originalcamerapos.x,newcamerapos.x,self.smoothness/Time:GetSpeed())

newcamerapos.y = Math:Curve(originalcamerapos.y,newcamerapos.y,self.smoothness/Time:GetSpeed())

newcamerapos.z = Math:Curve(originalcamerapos.z,newcamerapos.z,self.smoothness/Time:GetSpeed())

self.entity:SetPosition(newcamerapos)

self.target:SetPickMode(targetpickmode)--return pick mode to original value

end

Share this post


Link to post

Thanks Rick , i will try that tonight :)

 

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

 

Could we have some character movement later ?

Only orientation and simple move in space with mouse for direction if possible (no animation and other AI states)

I mean a moving cube, to keep code as simple as possible

Share this post


Link to post

Share this post


Link to post

Thanks, it's a start.

I notice that when attached to a camera, it makes the camera slowly but 'continuously' move (when the keys are not pressed).. I tried adding mass to the camera to stop it without success. Any ideas how it can be stabilised?

 

Weird, I can't seem to recreate this. For me the camera just floats in mid air. If you zip a copy of your project and msg me with it I'll open it and take a look.

Share this post


Link to post

Weird, I can't seem to recreate this. For me the camera just floats in mid air. If you zip a copy of your project and msg me with it I'll open it and take a look.

Message with link sent.

Share this post


Link to post

@Chris :

When you'll have time, if you could post some lines about Mouse to manage direction of the character ?

Share this post


Link to post

@Chris : thanks we have the free camera system now.

 

For rocket launcher code,, what would you use ? a rocket we put below ground and just place after weapon when player fires ?

For collision Axis box collision between rocket and mob ?

Share this post


Link to post

@Chris : thanks we have the free camera system now.

 

For rocket launcher code,, what would you use ? a rocket we put below ground and just place after weapon when player fires ?

For collision Axis box collision between rocket and mob ?

 

In the editor I'd create a rocket model, set it's physics shape and collision type, attach a particle effect, and then save it as a prefab. Then in code I'd use the prefab load function:Prefab

 

@Chris :

When you'll have time, if you could post some lines about Mouse to manage direction of the character ?

 

If I can find the time, maybe. What sort of mouse movement are you thinking of?

Share this post


Link to post

Thanks for the tip on prefab.

 

the fisrt would be some 360 direction input by mouse for the character or for some space ship :

 

On Android instead of mouse it would be some full 360 Android circle pad.

 

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

The second idea was but for later would be some RTS style unit movement :

You click on terrain or any model level with mouse and your unit or character goes to that position.

Share this post


Link to post

Thanks for the tip on prefab.

 

the fisrt would be some 360 direction input by mouse for the character or for some space ship :

 

On Android instead of mouse it would be some full 360 Android circle pad.

 

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

The second idea was but for later would be some RTS style unit movement :

You click on terrain or any model level with mouse and your unit or character goes to that position.

 

I'm just going to quickly post these 2 bits of code:

 

Top Down Camera:


Script.target = nil--Entity "Target"

Script.distance = 10--float

Script.debugphysics = false--bool

Script.debugnavigation = false--bool

Script.pitch = 20--float

Script.height = 10--float

function Script:Start()

if self.target==nil then return end

 

--debug functions for viewing physics or navigation in game

self.entity:SetDebugPhysicsMode(self.debugphysics)

self.entity:SetDebugNavigationMode(self.debugnavigation)

 

--Set the camera's rotation

self.entity:SetRotation(self.pitch,0,0)

end

function Script:UpdatePhysics()

 

--Exit the function if the target entity doesn't exist

if self.target==nil then return end

 

--Get the target entity's position, in global coordinates

local p0 = self.target:GetPosition(true)

--Calculate the new camera offset

local offset = Vec3(p0.x,p0.y+self.height,p0.z-self.distance)

 

--Add our original offset vector to the target entity position

p0 = offset

self.entity:SetPosition(p0,true)

 

end

 

Character movements: (on a goblin model)

 


Script.camera = nil --Entity "camera"

--Define animation sequences

Script.sequence={}

Script.sequence.walk=5

Script.sequence.idle=6

function Script:Start()

self.currentyrotation = self.entity:GetRotation().y

self.modelrotation = -90

App.window:ShowMouse()

end

function Script:UpdatePhysics()

local window = Window:GetCurrent()

local move = (window:MouseDown(Key.LButton) and 1 or 0)

local playerscreenpos = self.camera:Project(self.entity:GetPosition(true))

local mousescreenpos = window:GetMousePosition()

local vectorbetween = mousescreenpos - playerscreenpos

 

self.currentyrotation = Math:ATan2(vectorbetween.y, vectorbetween.x) + self.modelrotation

self.entity:SetInput(self.currentyrotation,move,0)

if move ~= 0 then

self.entity.animationmanager:SetAnimationSequence(self.sequence.walk,0.04,200)

else

self.entity.animationmanager:SetAnimationSequence(self.sequence.idle,0.05,200)

end

end

 

To understand the code basically

Math::ATan2 finds the angle between the mouse and the player

Camera::Project takes the character position in global space and converts it to screen space.

Share this post


Link to post

thanks a lot Chris :)

That's heavy pieces of code, and i would like to test if i can make some space game like this one.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...