Teardown

Teardown

Tameable Dragon
Geneosis  [developer] Mar 12, 2023 @ 12:06pm
DEV NOTES
Well looks like I reached the character limit in the main mod description, so I will have to write my dev diary here instead XD
Originally posted by About this mod:
One month after looking for someone able to build a dragon model that I could use, here we are :D
A "Dragon Pet" mod is one of the first modding ideas I had for Teardown, but I never started it as I was (and I still am) pretty bad at making voxel models, especially articulated ones... So I was hoping someone would eventually share one on the workshop that I could reuse but it didn't happen...
So about one month ago I decided to make a call in the Discord discussions, and not so long after I got an answer from TeardownDestructionClips who already had an Ender Dragon model pretty much reay to use and who agreed to share it with me ^^
So starting from this model, I started building a script to control the whole dragon body. I was a bit concerned about animating it as I had never really done that before, but I managed to get some simple animations working by simply enforcing some values in the body joint angles.
When I got a satisfying animation for every potential action the dragon will have to do, I started programming some generic commands that I could then be useb both by the player when riding (driving) the dragon and by the dragon AI when not controlled by the player.
To debug those I added the vehicle controls at the same time so I was able to ride the dragon, press some buttons, and see if it was acting as intended.
One of the first behavior I added was heavily relying on this shared command system: the taming mini-game. In order to tame the dragon I wanted the player to cancel the dragon movement, so I was able to send some command forcing the dragon to go left for example and if the player did press right at the same time, it would negate the whole movement.
At this point I had a flying dragon able to land pretty reliably but with no other ability yet, so I started thinking about a way for the dragon to grab item and transport them. Origially I thought about making it grab the objects with its front legs, but it would eventually result in crusing the object to brab when trying to land near it :/ So I ended up having the dragon bite on the object in order to grab it. In order to stick to the object but also be able to drop it easily, I used the ingame joint system to attach the object to grab to one of the dragon body parts when it is close enough. I had some issues with this as well as making joints too large can lead to the joints sticking to the wrong shapes, but I eventually figured out a way to get a precise link with some more help from other modders on Discord ;)
Grabbing stuff and dropping it down is fun and all, but what would be a dragon without firebreath right? As I originally had in mind Toothless as a model for this mod (and also because it's way easier to program this way :p) I decide to go for some fireball launch instead of an actual fire breath. Nothing fancy about the fireball itself, it just travel in straight line until it hits something and explodes... And it has some nice colouring system that tries to scale the explosion size with the flame heat temperature: going from not so hot red-ish flames to very hot blue-ish flames. I also considered making the fireball be thrown always at cursor position, regardless of the dragon position, but I decided to make it a bit more "realistic" by having the fireball trajectory be dependant of the dragon head angle, so the dragon cannot throw fireballs backward X)
With this fireball complete, I had the full range of base behavior I wanted when riding the dragon. Then I could start adding some AI behavior for when the dragon was not mounted. First behavior of course is to fly around in a seemingly random pattern. Not much to say about that part, I just send the forward command to the dragon and periodically make it turn to face a new direction. I simply added some special case to make the dragon progressively turn back if it goes out of the map to avoid losing it completely :p
When I had a nice straight flight pattern, I added some obstacle avoidance logic to it, just in case players want to make it fly really low to the ground ;) This took quite some time to tweak as I was trying to limit the number of raycast to the bare minimum to potentially be able to support multiple dragons on the map at once without insane lag. Honnestly I am quite happy with the result, the avoidance works really well in most cases and may only fail at avoiding really thin objects, which is fine.
Now that the dragon could fly relatively safely anywhere, I started adding the player orders: first one being to fly to a given location. I also noticed that this order would do nothing when the dragon was already at the designated location, so I decided to make the dragon land if it received the same player order.
I also wanted to have a way to call the dragon back to me, but this part required a slightly more technical algorithm: I wanted to find a clear landing route for the dragon so that it would not break anything on its path to the ground. This behavior would then be reused later for other reasons for the dragon to approach the ground. Once again, trying to limit the number of raycast, I made a cool area scan system that detects pretty accurately if the way is clear to a given landing spot, and if it's not, the dragon circles around the spot to try and find a better approach angle.
Once the dragon could go near the ground, I reused that ability to process the grab order from player. The dragon was then able to find a clear spot arund the object to grab, land near it, then trigger the grab sequence to try and stick to it.
Not forgetting about the fireballs, I also added the order to throw them at the cursor position if the plyaer orders it. The behavior is pretty similar to when the player rides the dragon, but the dragon AI also tries to get a better angle of view torward the target by flying back or up.
Then came the funny part: hunting! So hunting is bacically the same as grabbing an object, except the object is a movin target, and has a special tag that the dragon consider as food ^^ It also means the dragon is way less cautious with its landing when hunting and may approach its prey at really high speed. Once the dragon catched a prey, it will keep it in its mouth for a few seconds, and then eat it (breaking it into peices).
That was the first AI-triggered action I added to the dragon, the second one was to make it look for a landing spot to rest a little after flying for too long: this is basically using the scan algorithm I described above to find a clear area and land in it.
Here I had completed all of the behaviors I originally planned for the dragon, but the more I kept working on it, the more I felt like some people would want the dragon as a proper enemy, and not only as a peaceful NPC flying around... So I added more!
First of all the dragon is fully unbreakable, because without it it would probably break itself through its own animations or upon landing. Which means the player could not really damage it with weapons... Until I added the armor system! Basically just a health bar that decrease every time the dragon is shot or is hit by an explosion.
As I was building this armor system I noticed I had some useful information like the bullet flight direction or the explosion center, and I figured I could use those to approximatively determine the source of the shot. Meaning the dragon learnt how to fire back! If it is shot, it will throw a fireball in the direction where the shot came from ^^ This is a bit less accurate with explosions, but it is still nice to see the dragon react to getting hurt ;)
Then the next step torward a challenging enemy AI was to have a dedicated section to find and fire at the player! So in order to do that, I made the dragon remember the last known player location, and as long as the player is in sight it will shoot fireballs at him. Then when the player is no longer visible, it will go fly around the last known position to attempt to find the player again (using the same scan algo one more time). This was working pretty well, but with not enough accuracy for my taste, so with some more help from Discord I managed to get a good formula to compute where the player will be if it keeps moving in the same direction and then shoot the fireball there.
Finally, after I had this working player tracking behavior, I thought that it would be a waste not to use it against other bots in the game XD So I made a list of enemy tags for the dragon, so that it will start attacking them the same way it attacks the player if it has nothing else to do :p
A few more bug fixing later, I was finally done... Time to release the Dragons in the skies of Teardown!
Last edited by Geneosis; Mar 12, 2023 @ 12:21pm
< >
Showing 1-12 of 12 comments
lowwing Mar 24, 2023 @ 4:09pm 
wow someone needs to make a tldr(too long didnt read)
Rex Mar 25, 2023 @ 1:49am 
Remove tame minigame it bad remove it = le' best mod, keep it = le' worst mod.
Geneosis  [developer] Mar 25, 2023 @ 4:07am 
@lowwing: Well this is only for people curious about the process behind creating this mod ^^ It is fine not to read it at all if you are not interested :p

@Rex: This thread should contain all you need to know ;)
jakewohlander Mar 25, 2023 @ 10:56am 
I CANNOT SPAWN THEM IN
jakewohlander Mar 25, 2023 @ 10:57am 
i litterally can't it keeps telling me to enable them but when i do and then try to spawn it it says "Cannot spawn dragons yet, enable mod in menu."
Geneosis  [developer] Mar 25, 2023 @ 11:15am 
@jakewohlander: It tells you to enable the mod and then tame a Dragon, if you need help on how to do that please read this ^^
Last edited by Geneosis; May 8, 2023 @ 12:24am
beastred2g Mar 25, 2023 @ 3:27pm 
how do i go to the options
Geneosis  [developer] Mar 26, 2023 @ 1:58am 
@beastred2g: You know the mod menu where you select en enable mods? Right on top of the "Enable" button there is a button to open the options for that mod :) You can see it on the first screenshot on the main page of this mod ^^
beastred2g Mar 26, 2023 @ 10:40am 
thank you so much
Jacopo Jul 14, 2023 @ 1:05pm 
Hi man thank for your explanation, only one question,what programs did you use to code the movement,make the joints and more in general to develop the mod?
Last edited by Jacopo; Jul 14, 2023 @ 1:12pm
Geneosis  [developer] Jul 14, 2023 @ 1:12pm 
Originally posted by Jacopo:
Hi man thank for your explanation, only one question,what programs did you use to code the movement,make thd joints,ecc?
I did just use Visual Studio Code for the scripts, as I usually do ^^ I do not have any helper tool for the animations sadly, I had to do it the hard way by trials and error :p
Jacopo Jul 14, 2023 @ 1:13pm 
thank you so much man
< >
Showing 1-12 of 12 comments
Per page: 1530 50