moving Animated characters

Blitz3D Forums/Blitz3D Beginners Area/moving Animated characters

Pete Carter(Posted 2006) [#1]
ok i have got this almost working but im sure ive done it a hard way?

Id post code but it would have to be alot of my game so im sorry if theres not enough info to help.

the setup is main player character (a b3d animated mesh) with a 3rd person cam behind. im using an animation for walking forward (w) key and one for backwards (s) im using the mouses x for rotating the character and the camera left and right (also a different animation) and the mouse y to look up and down. (a) and (d) to sidestep (another animation). im having trouble with not all the animations working.


the problem is i walk forward, the animation plays fine then i sidestep and its just the first frame and the character sliding. ive used switchs like movef=0 and animf=1 etc to select what animations the character should be doing with each key press but it doesnt seem to work right.

does anyone know of a tutorial on how to get a character with lots of animations working or can explain a good way of setting this kind of thing up (say using the Psionic zombie as an example) not that im using it but i have a copy if anyone can give me example code.

prob asking alot please someone help.

Pete


cash(Posted 2006) [#2]
try this

first extractanimseq for all animations

then use

if keydown(whatever) then
if animseq(man)<>1 then animate man,1,1,1
endif

if keydown(whatever) then
if animseq(man)<>2 then animate man,1,1,2
endif

and so on


cash(Posted 2006) [#3]
also

if animseq(man)=1 then moveentity man,x,x,x
if animseq(man)=2 then moveentity man,y,y,y


Pete Carter(Posted 2006) [#4]
thanks ill give it a try! its only a bit different from how im doing it but it may make all the difference :O)

Pete


Pete Carter(Posted 2006) [#5]
how do you make him stop when theres no key pressed and play an idle animation. apart from that works great thanks :O)


stayne(Posted 2006) [#6]
if not animating(man) then animate man,1,1,1 ;idle animation

put that in your main loop.


Pete Carter(Posted 2006) [#7]
sorry he doesnt stop. i run the program and hes playing the idle animation you press forward and he moves forward animating correctly but when you let go of the key he keeps going ?


cash(Posted 2006) [#8]
This works for me, modify it to suit. Its a bit clumsy in terms of code, but effective. Notice I am using the =1 or =0 to register the keypress.

function moves()

If KeyDown(K_left) Then TurnEntity man,0,1,0
If KeyDown(K_right) Then TurnEntity man,0,-1,0

;WALK
If KeyDown(K_up)=1 And KeyDown(K_v)=0 And KeyDown(v)=0 And KeyDown(K_s)=0 Then
If AnimSeq(man)<>2 Then Animate man,1,.5,2
EndIf

;RUN
If KeyDown(K_up)=0 And KeyDown(K_v)=1 And KeyDown(K_s)=0 And KeyDown(v)=0 Then
If AnimSeq(man)<>3 Then Animate man,1,.45,3
EndIf


;WALK BCK
If KeyDown(s)=1 And KeyDown(w)=0 And KeyDown(K_v)=0 And KeyDown(K_v)=0 Then
If AnimSeq(man)<>7 Then Animate man,1,-.5,7
EndIf


If KeyDown(K_up)=0 And KeyDown(K_v)=0 And KeyDown(K_v)=0 And KeyDown(K_s)=0 And AnimSeq(man)<>1 Then Animate man,1,.2,1,4
If AnimSeq(man)=2 MoveEntity man,0,0,3
If AnimSeq(man)=3 MoveEntity man,0,0,5
If AnimSeq(man)=4 MoveEntity man,0,0,3
If AnimSeq(man)=7 MoveEntity man,0,0,-1
If AnimSeq(man)=8 MoveEntity man,0,0,1
If AnimSeq(man)=12 MoveEntity man,0,0,1
EndIf


End Function


Pete Carter(Posted 2006) [#9]
nice on i didnt know you could do (if keydown(44)=0) that should do it. you wouldnt beleave how odd and long my old code was to do what you have done in a few lines because i didnt know the right functions.

i wasnt quite sure what <> ment in your earlyer code i havent used it before i know what > and < mean on there own but not both together.

forgive me im a newbie with some bits and not others

Pete


stayne(Posted 2006) [#10]
If AnimSeq(man)<>7


translated: If AnimSeq(man) is less than 7 or greater than 7

it's easier to do it that way as opposed to:

If AnimSeq(man) < 7 Or If AnimSeq(man) > 7


I'm not sure if it's Or or And. I'm pretty sure it's Or.


Pete Carter(Posted 2006) [#11]
mate that function doent work (it says end if where no if?) you also have keydown(v) where i think it should be keydown(K_v) i think and you have keydown(v) = 0 or keydown = 0 right next to each other ? i dont how this was ment to work but it doesnt just changing the entity name for mine.

Pete


cash(Posted 2006) [#12]
I use the keys.bb include file so I dont need to know all the keycodes.

I wrote it pretty quick, but if you use the keys.bb file (search the samples and demos in your blitz installation folder for this file)it should work.

Each command should read keydown (K_something) not keydown (something). So yes there are a few typos here.

e.g

If KeyDown(K_up)=0 And KeyDown(K_v)=1 And KeyDown(K_s)=0 Then
If AnimSeq(man)<>3 Then Animate man,1,.45,3
EndIf

for each if statement there must be a then or endif to close it.


Ricky Smith(Posted 2006) [#13]
This may help :

http://www.blitzbasic.com/codearcs/codearcs.php?code=660


Pete Carter(Posted 2006) [#14]
smiff, could well do thanks again matey!