Third person controller

Blitz3D Forums/Blitz3D Beginners Area/Third person controller

Horax(Posted 2015) [#1]
Need an example (code - not asset) of the third person controller where model and animations (stay, walk, run, etc.) are loaded in separate .b3d files.
For now my progress is...



RemiD(Posted 2015) [#2]
You can also have all your animations in the same b3d file...

Personally i use LoadAnimMesh() to load the rigged skinned animated mesh, and ExtractAnimSeq() to load each animation, then i use AnimSeq(), Animate(), AnimTime(), to manage/play/stop the animations.

You can read the description of each function here : http://www.blitzbasic.com/b3ddocs/docs.php


Horax(Posted 2015) [#3]
I can load and animate my models. It's not a problem.
In my case I use LoadAnimSeq because all the animations are separate .b3d files (woman-stay.b3d, woman-walk.b3d, woman-run.b3d, etc.).
That's what i did:
AppTitle "CHAR_CTRLS"

Global screen_width = 1024, screen_height = 768
Graphics3D screen_width, screen_height, 32, 1

SetBuffer BackBuffer()
SeedRnd MilliSecs()
HidePointer

;data
Include "SOUND&MUSIC01.BB"
Include "LEVEL ELEMENTS01.BB"
Include "GUI01.BB"
Include "SCENE01.BB"

;object details
Include "GUI02.BB"
Include "GUI03.BB"
Include "LEVEL ELEMENTS02.BB"
Include "SCENE02.BB"

;called functions
While Not KeyHit(1)
RenderWorld()
UpdateWorld()
Include "GUI04.BB"
chr_ctrl()
Flip
Wend
End

;functions
Function chr_ctrl()
If KeyDown(17) = True Then MoveEntity model,0,0,1.25
If KeyHit(17) = True Then
   Animate model,1,0.4,walk
EndIf

If KeyDown(57) = True Then MoveEntity model,0,0,2.5
If KeyHit(57) = True Then
   Animate model,1,0.4,run
EndIf

If KeyDown(31) = True Then MoveEntity model,0,0,-1.25
If KeyHit(31) = True Then
   Animate model,1,-0.4,walk
EndIf

If KeyDown(30) = True Then TurnEntity model,0,1,0
If KeyHit(30) = True Then
   Animate model,1,0.4,stomp
EndIf

If KeyDown(32) = True Then TurnEntity model,0,-1,0
If KeyHit(32) = True Then
   Animate model,1,-0.4,stomp
EndIf

If KeyDown(16) = True Then MoveEntity model,0,0,0
If KeyHit(16) = True Then
   Animate model,1,0.4,stay
EndIf

End Function

My character can walk, run... but it's absolutely not a third person controller.


RemiD(Posted 2015) [#4]
I am not sure what you mean by "third person controller" ?
Do you mean a way to turn move the camera around the character ?
http://www.blitzbasic.com/codearcs/codearcs.php?code=2724
Do you mean a way to detect collisions between the character and the obstacles and reposition the character ?
http://www.blitzbasic.com/codearcs/codearcs.php?code=3141

About your code, i would put chr_ctrl() and updateworld() before renderworld()

And the Include "GUI04.BB" seems weird, Include "x.bb" is usually put at the top of the code, and then you can call a procedure function where you want.


Horax(Posted 2015) [#5]
RemiD, thanks a lot!
***
But... Maybe I'm not correctly explained my current problem...
The problem is:
When I Move my model - all works good.
When I Turn it - also good.
But if both Move & Turn - then plays the last AnimSec.
I understand it - it's all right - all works exactly as I wrote in my code. But it's absolutely not what I need.
And here (to understand how it must be) I'd like to look at the animating algorithm which working properly.
***
The Include "GUI04.BB" includes a set of functions. It must formalize & hide insignificant here strings of code.
***
Update
Function chr_ctrl()

If KeyDown(17)
  MoveEntity model,0,0,1.25
  If AnimSeq(model)<>walk Animate model,1,.4,walk,1
Else
  If AnimSeq(model)<>stay Animate model,1,.4,stay,1
EndIf

If KeyDown(30) = True Then TurnEntity model,0,1,0

If KeyDown(32) = True Then TurnEntity model,0,-1,0

End Function

Now I have the properly working choice of stay / walk AnimSeq.
I think I am on the right way...
***
Update
It is not the ultimate decision. But for now I shared the "chr_ctrl()" elements between two functions, "chr_move()" and "chr_turn()".
Is what I have:
Function chr_move()
If KeyDown(17)
   MoveEntity model,0,0,1.25
   If AnimSeq(model)<>walk Animate model,1,.4,walk,1
ElseIf KeyDown(57)
   MoveEntity model,0,0,2.5
   If AnimSeq(model)<>run Animate model,1,.4,run,1
ElseIf KeyDown(31)
   MoveEntity model,0,0,-1.25
   If AnimSeq(model)<>walk Animate model,1,-.4,walk,1
Else
   If AnimSeq(model)<>stay Animate model,1,.4,stay,1
EndIf
End Function
Function chr_turn()

If KeyDown(30)
   TurnEntity model,0,1,0
   If AnimSeq(model)=stay Animate model,1,.4,stomp,1
ElseIf KeyDown(32)
   TurnEntity model,0,-1,0
   If AnimSeq(model)=stay Animate model,1,-.4,stomp,1
EndIf
End Function

The "chr_move()" function works good; the "chr_turn()" function - work in process.


Horax(Posted 2015) [#6]
Is what I have for now:
;functions
;chr_move()
Function chr_move()
If KeyDown(17)=True
   MoveEntity model,0,0,1.25
   If AnimSeq(model)<>walk Animate model,1,.4,walk,1
ElseIf KeyDown(57)=True
   MoveEntity model,0,0,2.5
   If AnimSeq(model)<>run Animate model,1,.4,run,1
ElseIf KeyDown(31)=True
   MoveEntity model,0,0,-1.25
   If AnimSeq(model)<>walk Animate model,1,-.4,walk,1
ElseIf KeyDown(scancode)=False
   If AnimSeq(model)<>stay Animate model,1,.4,stay,1
EndIf
End Function
;chr_turn()
Function chr_turn()
If KeyDown(30)=True
   TurnEntity model,0,1,0
   If AnimSeq(model)<>walk Then
      If AnimSeq(model)<>run Then
         If AnimSeq(model)<>stomp Animate model,1,.4,stomp,1
      EndIf
   EndIf
ElseIf KeyDown(32)=True
   TurnEntity model,0,-1,0
   If AnimSeq(model)<>walk Then
      If AnimSeq(model)<>run Then
         If AnimSeq(model)<>stomp Animate model,1,-.4,stomp,1
      EndIf
   EndIf
EndIf
End Function


The model can walk, run, walk back... but not stomp at place.
What's wrong here?
***
Update
Finally I did it.
The chr_ctrl() (character_control) function is:
Function chr_ctrl()
If KeyDown(17)=True
   MoveEntity model,0,0,1.25
   If AnimSeq(model)<>walk Animate model,1,.4,walk,1
      If KeyDown(30)=True
         TurnEntity model,0,1,0
      ElseIf KeyDown(32)=True
         TurnEntity model,0,-1,0
      EndIf
ElseIf KeyDown(31)=True
   MoveEntity model,0,0,-1.25
   If AnimSeq(model)<>walk Animate model,1,-.4,walk,1
      If KeyDown(30)=True
         TurnEntity model,0,1,0
      ElseIf KeyDown(32)=True
         TurnEntity model,0,-1,0
      EndIf
ElseIf KeyDown(57)=True
   MoveEntity model,0,0,2.5
   If AnimSeq(model)<>run Animate model,1,.4,run,1
      If KeyDown(30)=True
         TurnEntity model,0,1,0
      ElseIf KeyDown(32)=True
         TurnEntity model,0,-1,0
      EndIf
ElseIf KeyDown(30)=True
   TurnEntity model,0,1,0
   If AnimSeq(model)<>stomp Animate model,1,.4,stomp,1
ElseIf KeyDown(32)=True
   TurnEntity model,0,-1,0
   If AnimSeq(model)<>stomp Animate model,1,-.4,stomp,1
ElseIf KeyDown(scancode)=False
   If AnimSeq(model)<>stay Animate model,1,.4,stay,1
EndIf
End Function


The model now walks, runs, walks back & stomps (when rotates) at place.
And certainly - without player input - it stands & breathes.
Thanks to all for your attention!