Having conquered "doors", I decided to move on to a new problem. Enemies.
Love them, hate them, know that they're always plotting your demise.
The lack of depth in this is a bit tricky, but the yellow portion is the fixed base. The red section can rotate freely allowing left/right directions. The green which would also be the business end of the weapon, can swivel up and down. A 2-axis pan/tilt system.
You can see the small-ish turret in the game scene. I need to fix the normals on the yellow base so they are properly pointing outwards. The blue/teal sphere was part of my initial solution. I was going to apply a constraint to the it that it was always looking at the player's ship. Then I could just take each individual rotation and apply it to either green or red, so that I didn't need do to the math myself.
That didn't work out so great, so I had to figure out the math:
That’s the top down perspective of my Level Zero. I need to at all points figure out what the angle is between the selected object (my turret) and the ship which is located at (1,1,0). This view is directly on top so you do not have any indication about the Z
axis which is the height.
I need to figure out what angle I need to rotate so the red section is facing the ship. Trigonometry to the rescue. Then I do the same thing to figure out the relative height difference for the green section.
α = arctan((turret.y - ship.y ) / (turret.x - ship.x))
Great. Then for my green object I care about the X and Z axis as I need to know how far, and what the height is.
α = arctan((turret.z - ship.z ) / (turret.x - ship.x))
I have to take in to account things like scale and rotation, but there are things designed to do that for me. Let me give this a go.
Left is the turret aimed at a space where the ship was. Right is after it has been told to point at the ship.
I can animate it as well and it looks pretty cool.
I spent a decent amount of time trying to figure out how I wanted the turret to work, maybe I'd give it legs so it could scuttle about. After spending some time looking into how you'd get animations working in SceneKit and exporting those from Blender, I decided to move on.
I returned to what Descent has for enemies:
That’s a model of an enemy from one of the Descents.
It doesn’t have articulated moving animations, it just floats and shoots at you.
I thought the turret route would be easy, but adding legs was probably not the way to go.
I decided that I was going to name all my enemies after Mustelids, your weasels, badgers, otters, ferrets, minks, wolverines, and martens.
Behold the Marten, it’s just a boxy thing with guns, but sometimes the classics are best.
I might have to scale it up, but it shows up. There’s just two on the map right now. I think once I can get them to orient towards me, which might be really easy since I just need to turn the entire model not worry about discrete components. I did leave the “weapon pods” their own nodes so I could in theory tilt them up/down and to the left/right if I thought that would make things look better. Actually the small size will help with that, because they almost always can just fire directly forward if they’re smaller visually.
I wrote at the time:
It’s very cool to see them slowly rotate to face me based on the animation duration and when it updates. I can at this point figure out how I want the firing animation to look like, and because they’re facing the ship I can have them fire “forward” and I get to go home early.
The other thing you need to be an effective enemy, ostensibly on an asteroid mine, is a powerful laser weapon.
SceneKit has particles that I made into an effect:
Which allowed me to add them to the Marten:
Applied to the Marten already in the level:
And I made the laser more additive and added some orange tones:
The one thing I quickly identified was that having four weapon barrels was a tremendous mistake on my part. I should've kept it at two.