Squircle Resolved

At the end I had to give up on calculating my squircle by hand.

Two reasons

  1. Unity gives an automatic way to approach the problem;
  2. The tool Unity gives works with any (some kinds of any) type of shape, not only with geometrically correct squircles

I ended up using ray casting. I feel like I cheated, but.. that’s life. On one hand, I don’t have the nerve to develop the maths to deal with the problem myself, so… see reason 1. On the other hand, I have the consolation of working with shapes even better than a squircle.

Here’s how it goes:

You have a player somewhere on the map and a list of objects you want to track on your compass.

On the minimap you see the player himself. He always keeps his Noth-bound position, so when you rotate, you see the map rotating around you. Each trackable object (if not close to be seen on the minimap itself) is represented as an icon on the border of the minimap. The border is the ‘compass’.

You get the angle between the player forward position and the object in real world, then create an icon on the compass and place it on the compass, keeping the same angle between the up position of the canvas and the icon. The problem is the distance between the icon and the center of the minimap.

Here’s what you do – you have a secret object, outside of the playing area, that is basically a 3d version of the shape of your compass. That’s your ‘wall’. It’s hollow. In the middle there’s a radar object with a small script. You give that script the angle ‘in the real world’ between the player.forward and the object. The radar fires a ray at that angle and returns the distance to the wall at that angle.

You get that distance, scale it accordingly and give it to the compass.

If feels clunky to have a real world object that scans constantly to get the distance, but it undoubtedly works and it works with almost any shape, at that. The only limitation for the form of your compass and minimap is that the border can not swerve to an extend that one part of it blocks line of view from the center to another part.

Here’s the physical object with the (invisible) radar in the middle.

The radar is currently tracking 6 objects from the map, using angles, provided by the map itself. The visible rays are Debug.DrawRay().

Here are the map and the radar complex, set aside it:

You can clearly see that I haven’t even bothered to set the anchor points of the objects to the centers of their bases. I am tracking their basic 0,0 vertices here. Irrelevant.

Here are both the scene view and the play view:

All colored objects are on the compass. The compass itself is the blue band around the minimap.

This was just a feature-dev scene, so I didn’t bother matching colors of objects to icons. Black icons are blue objects. Yellow is yellow.

So… this has not yet been transferred to the main scene. In the full version you have multiple type of objects that you can see on the compass, some only from a certain distance. All of them should disappear from the compass if there are actually seen in the minimap (here you can see the yellow object bot on the map and the compass).

This step of transferring the compass success to a ‘main scene’ type of actual structure will be hell…

 

Uuhh!! Look what I found ShareX can do!

Screen recording! And – Tadaaaa!  – Screen recording to GIF!

TankUp: Describing the environment, part 2

What I’ve been pondering about the last few days is the question how to build a fingerprint of the environment of the AI Tank, once its sensor has taken down the data.

For now what the tank is interested in is the following:

  1. how many enemies are in teh vicinity (in sensor range)
  2. what is the total size of the enemies
  3. how big is the biggest enemy
  4. are there any layers in range
  5. are there any upgrades in range

Once I have the data I’d like to boil down that into a simgular piece of information that I can pass around and compare through time. Obviously an object would be… adequate. May be even a struct, as this is only a collection of data with no behaviour. However, I might still need a fingerprint I can fit into a single value type variable – Iwant to be able to easily compare it’s contents in t-0 and t=1 and say “something has changed, make a desicion about a possible change of behaviour”.

My usual go, given the fact that all the relevant information is expressed in integers, is to line them up one after another and read them as one larger ingeter, but that, for the moment, seems clunky. Is it?

TankUp: Describing the environment

Concerning: The way the AI Tanks describe their environment.

I just put in place the class that will be used by the tanks to note down the specifics of their environment. An instance of that class, filled in with a couple of GameObject lists (one for other combatants, another for pickups), a simple int for the current stack size of the tank and (very important) a fingerprint of the entire content of the environment object instance.

That last part is there to avoid unnecessary shuffling of data. The tank will always keep the object up to date in order to pass it to the State Selector static class and get back a verdict on whether state change is needed. However, I’d like to do that only if necessary. So at regular intervals the tank will refresh its environment object, get the fingerprint and will bother the state selector only if the new fingerprint differs from the latest one. This seems to be a reasonable way to do it.

Also, about the state selector – a static class seemed fine. No state of it’s own (how ironic 🙂 ), something like ‘WWJD’ – what state would you choose if you were me and this was your immediate context 🙂

P.S. Something is wrong with the whole thingy – wether the IDE or Unity is behaving. I updated Unity to 3.0f6, then VS said – what is this ‘TextMeshPro’ you speak of? I expected a whole metric ton of .csproj files to have already been loaded for this project. Therefore you have 200+ errors. The game project is running, though, so I don’t know… I dialed it back to 3.0f5 and the problem remains. We’ll see when I try it at the PC at home.