Best way to have dynamic legs for structure.

I have a turret and I want to know how anyone else would handle the design and/or the animation behind it (as one informs the other I bet).

I want to have the turrets be placed into the scene by the player but the terrain is uneven, so when the turret is placed it has to deploy its legs so that the tip of each one finds the surface of the world and stays there to give the illusion that they’re holding the unit up.

My initial thoughts were to make a leg with bones and a joint at the ‘body’ and the ‘knee’ and somehow make the tip of the leg (the ‘foot’ send a raycast and head to the vector3 that is returned.
As im fairly new to unity scripting I was just wanting to see how you guys would handle this before I finsh modelling the turret in case there’s some amazingly simple idea i could model into it to avoid problems later :slight_smile:

fortunately there is indeed an amazingly, amazingly, simpler way.

Just have “a leg”. …

you can easily change the “length” of the leg by just seting the localScale.

here’s an amazingly detailed answer

pls vote up useful answers! :slight_smile:

Yes you could use a skinned/boned model with one (or more) “knees”. You would have to use inverse kinematics or a simple form of inverse kinematics to determine how the legs should bend.

if you need to become an inverse kinematics engineer, begin with books, tutorials, available packages etc, search on all questions here on the topic and so on.

one problem is if you do it that fancy way, it still won’t work in all situations, as the desired lenth could be too short or too long for your leg.

the very simple approach I explain above will work perfectly in all situations.

obviously, you may have (say) a separate perhaps “foot” - no need to scale that part - and the actual leg part of the leg, that’s the part you’d scale. (Alternately your artist may be able to pull off the leg so that it’s simple one piece that looks fine when it is scaled along its length.)