OC – Dev Sketches

It takes time to make a mod in Teardown. Sure, you can just belt something out and push it on to the workshop, but the mods that seem to endure are the ones that had more than just 15 minutes spent on their design.

I’m a visual person, so when I’m working I like to sketch out things to figure out a specific problem, or just to have a visual representation of a bit of code that I’m working on. It keeps me on track, and is a valuable tool to double-check that I’m attacking something properly to solve it.

Here’s a few of the drawings I made while making the Omnicar, with some brief explanation of what is going on.

Remember Trigonometry? I sure didn’t, so I had to get some brush-up courses and relearn a few things. (I picked up a good deal via Humble Bundle for Gamedev dot tv “Math for games” courses. Cost me $5 bucks, lol.) One of my problems was locking a plane of coordinates to an arbitrary moving target, which required a few calculations. This diagram is basic Trig, properties of Sine/Cosine and how they relate to a unit circle.

The degree markings are how they are represented in-game. In Teardown you get 180 degree plus/minus, switching over at the 0 mark. The quadrants just represent which is positive at that degree of the circle, which helps with troubleshooting things.

Oh hypotenuse, we hardly knew thee! Seriously though, this came out to be more useful than I originally anticipated. Figuring out angles using right-triangles is quite easy and Hypotenuse lengths are useful if you’re doing things around an origin point.

The heavy-lifting of calculating tangent coordinates. I wanted to put sprites on a row of these, so they’d stay with the car and be properly perpendicular. I had to do some other steps that I don’t outline here, but this diagram helped me quite a bit to get it going.

Do you like dynamically resizing sprites? I sure do. This was the hairy bit that I had to figure out with the existing tangent coordinate calcs. Bunch of values that I was working with on a test case, just to make sure that I had it all nailed down before feeding the Sprite Renderer coords and values.

I went through quite a few iterations on how to make the “skateboard” design drive more consistently. Initially the rear of the car would pivot and overtake the front, spinning it around at times. It was very “loose” in its characteristics, so I had to design something that would dampen the Y-Sway. I’m happy to say that I came up with something that worked out.

Using any of the API functions that contain the “Constrain” keyword can yield some rather hilarious results. At one point, I tried a test where it immediately turned the car into a whirlwind of broken parts ascending into the sky. That was quite funny, now that I look back on it.

Figuring out acceleration curves. From what I can tell, most vehicles in Teardown use a linear acceleration model. That works for most things, but I wanted something with a bit more finesse. Enter Quad Bezier curves! With a start, mid, end point I could make a curve to my liking.

The real trick was doing the rescaling needed to take arbitrary bezier 2D coordinates and make them relate to the speed I was adding to my vector forces. That, and making a timer mechanism that allowed me to control the duration of the curve itself, feeding the Bezier function “live” so it would return a proportional speed value in relation to the maximum speed limit.

Did I tell you it got complicated? Oh yeah, it sure as hell did. But it works, so that is what matters. Its pretty nice to be able to “nudge” the forward control and get a smooth rise in speed – so you can control things on the low-end but also do a full burnout to maximum.

Did I mention the bezier curve is adjustable? Oh yes, it is. I haven’t put a visualization of it in the UI, but its in there.

There’s more to come as I complete things. I think I’m at the 90% stage in the project, which means I’m getting impatient to finish and I want to work on something else. I’ll get there though and release it, I promise.

Until next time…

OC – The “Skateboard”

Where I left off in the last post, I mentioned that I had to use “game logic” to figure out a good way to get the ball wheel design working. Funny thing, I did exactly that. In the real world, we don’t have things that can pass through other objects like a ghost. It might be handy, but that kind of thing isn’t part of our reality.

After pondering the roller/cage problem for a while, I realized — I was thinking in too literal a fashion. I didn’t have to make a containment system like I would if this was a physical object. The solution was to have a support strut that went into the center of the sphere wheel with a ball joint at the end.

The result looked like this:

Why red support struts? Just for visibility so I could see what was going on…

In the background there you can see the blue crane-like rig I used to figure out if the wheels would work at all. It was fun putting it together and making it move around. I call this design the “Skateboard” because there is absolutely no way to directly power the wheels. I was stumped for a bit until a fellow modder Dima helped me out.

The answer? I was trying to apply Body Impulses using the modding API to the frame, but the results were not what I had hoped for. Dima showed me that applying vectors of force to the pivot was the way to go, in addition to using Constraints so the speed didn’t get out of hand.

With that under my belt, I was able to hack something together that not only used a “front drive” but something I like to call “crab drive” — where force is applied to the center of mass so all the wheels turn in the same direction. Think parallel parking and you want to go sideways into a spot. Well if this was on your car, you would have no trouble at all.

Demonstrating front drive mode, then crab mode. Watch the difference in steering.

Not bad, but I’m sure you see the problem in front drive mode — the rear wheels tend to just roll with momentum so sometimes they start to overtake the front and rotate the entire body. That isn’t something I wanted. Crab mode however is rock solid because center of mass is a pretty stable place to apply forces from.

This was my first problem – how to use front drive mode without the back end swishing everywhere? Some might prefer the out-of-control feel of driving that way, but I knew most would be expecting conventional drive, where small adjustments to steering didn’t cause the back end to shimmy all over.

After some research I realized that I needed to apply some counter-force to the rear of where the front drive forces were being applied. In Teardown, the pivot point of the body determines where those forces get placed, unless you calculate the center of mass like I had.

So this meant I needed to figure out how to create a virtual pivot point to apply forces so the tendency to turn/swivel after each forward push was minimized. Let me tell you, that wasn’t too easy. I never had higher math courses and I’ve only recently dove in to Trigonometry, like this diagram below from Gamedev dot tv:

Is your brain melting yet? Oh trust me, it will…

That diagram shows what is needed to solve an arbitrary angle using math for a right triangle. Yep, games have lots of math in them, but its all hidden away in functions and other bits.

I had to figure out somehow this “Virtual Pivot” problem before I could even hope to stabilize the driving behavior of Omnicar.

(To be continued)

OC – Prototyping

I get ideas from all kinds of sources. Sometimes, I see something neat in a movie, or I look at a website and there’s a cool concept that spurs another idea in my head. Well, I was puttering around and found this video via Hackaday of a lego-ball-driven car.

Bright sphere wheels and some lego motors, what is there not to love?

I have a project list, so I can jot down an idea and assign it a number. I don’t do these sequentially, typically I follow the classic pattern of Teardown (or any other game) modding:

I do actually finish some of them. I do like to rotate between different projects when I feel I’ve hit a wall, or I just am sick of looking at the same thing for months on end. That break usually allows for more thinking about how to improve things in general.

This particular idea was number 25. (As of this writing I have about 47 ideas and I add to that on an ongoing basis.) The concept was interesting to me for a few reasons:

  1. There is a built-in vehicle system/entity in Teardown, but its a bit finicky and it is very easy to crash the editor if you don’t get everything just right.
  2. The vehicle entity requires a setup that is Magica-native, in terms of a compound model with shapes nested in its structure. (Yet another thing I really don’t want to mess with. I like Qubicle anyway.)
  3. Vehicles have some limitations when it comes to behavior of lights – they only turn on when you’re driving, for instance. There are some hacky ways around it, but I didn’t like any of those approaches.
  4. Driving using regular wheels means accepting the suspension/turning design, it is very hard to change that substantially with the vehicle entity.
  5. Omnisphere wheels are cool as hell, and enable neat tricks like “Crab Mode” when driving.
  6. I could make my own light systems and control them however I wanted, including everything else, like chase cams, etc…

So omnicar it is!! My first attempt was rather — plain. But you have to start somewhere, right?

The vertical bits were to keep the spheres contained, but I figured out a better way later on.

For all intents and purposes, this was the base chassis of the car. Those wheels? I know they look a bit clunky, but the Teardown engine treats individual voxel cubes as spheres for collisions, so I knew they would roll okay. I just had to figure out how to get that done.

This involved making a in-game test rig, where I messed with joints (an entity type that does what it says, links two parts together with varying degrees of freedom) to find the optimum solution. My first try was a cage-like system lined with rollers, but that didn’t perform too well.

The collisions would slow things down and generally it was really clunky. However, I did come up with something — I just had to apply “game logic” to my design process.

(To be continued…)