Physics Phrustrations and Chaotic Connections

Physics Phrustrations and Chaotic Connections

Well hello lovely people! It’s that time again. Not only is it blog day, but the weather is finally turning! Hope you are enjoying the sunshine. If you aren’t, you should be! Or, well, read this blog first. Then enjoy the sun! Let’s go for a recap shall we?

I’ve been focussing on internals again. I wasn’t happy with how the movement felt, so I’ve been playing around with the logic. Now, the simplest solution would be to just use Unity’s premade CharacterController right? Sadly, this isn’t possible. The character controller Unity provides doesn’t cope with the physics requirements we have. Grabbing and dragging objects in such a way that the weight of the object affects the player’s movement was proving taxing. It’s possible I may try again, as I’m still not wholly sold on the movement, but I have made some decent improvements at this point I think.

The next thing on my list was to make the dog feel a bit more alive, to get it closer to how the finished product might feel. I knew this would be temporary, so I busted out some quick Sine and Cosine curves to make the dog both oscillate and rock back and forth.

Background for non-techies: We fairly often fall back onto some common utilities when coding. The Sine and Cosine curves are good examples of this. If you hark back to GCSE maths, you may remember that these curves give you values ranging from -1 to 1, regardless of what angle you give the function. Now that “angle” doesn’t have to be an angle at all. If you perhaps apply Sine/Cosine to time, a number that is constantly increasing, you will get a smooth repeating loop from -1 to 1 like this:

See the source image

With Cosine, the value Cos(0) is 1, with Sine, the value Sin(0) is 0. So depending on where we want to start, we can choose different functions. To make something that oscillates from 0 to maxY (where maxY is any desired maximum value), we just multiply the function (let’s say “Sin(time)” for ease) by maxY: “yPosition = Sin(time) * maxY”.
Though that isn’t quite right, is it? That would oscillate between -maxY and maxY. Hm. Well there’s a simple solution! We just take the “absolute value” of Sin(time). The absolute value just removes the negative of a number. So Abs(-2) = 2. Sorted. We can also adjust how long a full loop takes by changing how quickly time increases. But I’m getting a little carried away now!

The first attempt of this wasn’t… quite right:

Seems like I got some of my initial values wrong. For a start, the duration of the curve appears to be a decade, and the rotation looks a bit funky. I played around some more and got to this point:

We’re getting there, but this isn’t a game about Bambi, so I made some final adjustments:

Lovely! As a temporary aid to get that doggy feel, I’m very pleased with that. An interesting thing to note here is that that movement doesn’t affect anything about the gameplay. The collisions and the grabbing are all the same. This can be best seen in the second video, where I collide with a box I’m 3 feet above. This is deliberate, as the movement is visual flair only, and because it’s temporary, the less it modifies the better!

The final thing I want to talk about is the UI changes. Using the event system I detailed in the last post, I have now hooked up a Chaos Tracker that keeps tabs on what damage you are wreaking and updates a bar at the top of the game. The bar itself is very simple. It just scales the fill out from the left to the right as chaos increases. An event tells it the max chaos in a level and another event tells it when the chaos is changed. The result looks like this:

You can see there are still movement issues here…

My next steps are to get the max chaos calculating itself, though as we’re planning on having objects all give different chaos values depending on how you use them, that might be more trouble than it’s worth! I’m going to go get on with that now I reckon, then make the most of the sun!

Matt out.

One thought on “Physics Phrustrations and Chaotic Connections

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
css.php