Okay so here’s a quick update: I got some animations in :)
I changed a whole load to get this working properly. I have scrapped structs for the npcs/spiders/cats/skellys etc, and now have loads and loads of arrays. So instead of entitylist[i].pos I have entitypos[i] instead. A minor change, but I think having such complicated structs was screwing things up somewhere, and this works, so good.
Also, another little thing which I think is cool is that I’ve written a small function that finds a model in the big list of 3d models I’ve got. There’s no ‘spidermodel = loadmodel(“quaternius/spider”) here - just one big array of strings of all the models, and another big array that I put all the results of loadmodel() into. I’ve got 90 models loaded now, which is cool, but I was having to scroll back to the start of my program and read through the list and make a note of it if I wanted to use a model, which was a) a pain, and b) meant I couldn’t insert anything at the start of my array due to it shifting everything following it. So now instead of hardcoding the model into the npc definition, I have a line that reads ‘entitymodel[i] = findTheThingInTheList(biglist,”spider”)’ and even if I modify the list, it still works! It even lets me know if it finds something more than once, or if it doesn’t find it in the list, which has prevented my cats from morphing into cattail ferns.
I’ve deleted all that stuff I had decorated my island with. They were just for testing anyway and it was taking ages to load. I wonder if there’s a better way. Minecraft loads things in in chunks as you’re playing. Maybe if I load things in it might be a more pleasant coding experience than having to wait for the whole lot to load in while looking at a blank screen (or even a loading screen). Something to think about anyway.
Animations are kindof weird. They’re measured in seconds, and represented by a float. There’s a few built in functions in fuze that gets the number of animations a model has, and their lengths. I have variables for currentanimation, animations (an array of lengths), currentframe, ‘walkinganimation’/‘jumpinganimation’ etc. (the different models have more or fewer animations, and not all in the same order), and a ‘stride length modifier’ that I’ll be using to make sure they don’t look like they’re skating or pedalling their legs. I’ve written a function called ‘animateEntity’ that takes in the array index of the entity, and a float representing speed, which updates the animation with the right values based on those variables I mentioned above making sure it loops properly. Tricky to get your head around at first because it’s not frame numbers you use in fuze, it’s a float between 0 and the animation length. Unexpected (for me), but once you grok it, it’s not so bad.
Anyway, that’s my update :)
Edit: one thing I forgot to mention is that I have ‘speed’ as an input into my ‘animateEntity’ function so that I can match the animation cycle to the actual speed they’re moving. That’s how those skeletons keep their feet planted firmly on the ground. They slow down their running as they slow down, type of thing. Doesn’t look so great on steep hills but Everywhere else it looks really natural :)
Speed is calculated using the distance() function, btw.
speed = distance( {0,0,0} , entityacceleration)
It gives you the length of the acceleration vector. Very handy to know.
I also changed their ‘point towards’ to ‘CurrentPosition+((CurrentPosition-PreviousPosition)*10000)’ - which keeps them pointing the direction they’re going (or close enough). Things get weird when you omit the *10000. Now when the cats run off cliffs, it looks like they’re deliberately diving down, and my spiders climb up and down slopes quite convincingly..