Part 27 - More refinements.

By Jamie Chatterton / 2018-06-12

I'm going to make a number of changes now to make the game a lot more realistic.

First… the way it drops coins.

It's not realistic

Just dropping them like it does.

Most games of this type drop them from a long upright panel and let them fall down vertically.

So I'll change it to do that.

First, changing the 'wall' object to be much taller…

Open this image in a new tabIncrease height of wall
Increase height of wall

Moving the spawner cube object up to the top of this. I have to change the grid snap to 0.5 to do this.

And deleting that left over coin.

Open this image in a new tabDelete left over coin
Delete left over coin

I want to now change how the coins spawn, from horizontally to vertically, flush against that wall…

Honestly I think the best way is to move it so that it's resting on top of the wall…

It's going to be hard to tell…

But looking from here… Rotating around X by 90 degrees, this face facing down

Open this image in a new tabMove coin spawner 1
Move coin spawner 1
Open this image in a new tabMove coin spawner 2
Move coin spawner 2

Becomes that face facing out.

Selecting the 'Spawn Location' it has become

Open this image in a new tabSelect Spawn Location
Select Spawn Location

It needs to move out slightly, so when the coins spawn, they spawn above the mid-air and not the 'wall'.

I set the position to -0.1, down it's location Y axis by 0.1, so it becomes

Open this image in a new tabChange spawn location
Change spawn location

However.. coins do not take into account the rotation of the SpawnLocation when they are instantiated… doh!!!

Need to change the code a little!

In the SpawnerControler we need to change the SpawnObject code a little…

void SpawnObject() {
  var coin = Instantiate(ObjectToSpawn, transform);
  coin.transform.position = SpawnLocation.position;
  coin.transform.rotation = SpawnLocation.rotation;

  OnSpawnCoin.Invoke();
}

The new line being...

coin.transform.rotation = SpawnLocation.rotation;

... so it picks up the rotation of the SpawnLocation object also.

And with that, it's immediately obvious that the position of the SpawnLocation is not quite enough… so I've set it to -0.11… and that works fine now.

This gives the following… I changed the camera angle

No explicit tag…

Git repository: https://bitbucket.org/hiveit/unity-tutorial-coin/src/685d91038df345086d35f4d1f95f6964ba9cae75/

There's an immediate problem with this, the walls need to be taller to stop coins falling off the side… so that's first…

Open this image in a new tabStop coins falling off sides
Stop coins falling off sides

Then let's make the front glass that channels the coins down… just duplicating a wall as a starting point and moving it into position.

After creating it and some adjustments to the width I've ended up with

Open this image in a new tabAfter some adjustments
After some adjustments

It's 0.2 units thick.

It plays like …

Which then starts screaming more problems.

Git repository: https://bitbucket.org/hiveit/unity-tutorial-coin/src/991156479cda11744e100965b895b809a4ebaa7f/

The platform shouldn't go all the way back…

Back to editing the animation.

Changing the maximum back-stroke of the pusher animation to just 5, in the Animation panel, you get the problem that the coins will pile up.

Possibly the easiest way to fix this is to move the base of the back 'glass' panel up slightly. This can be done by moving the whole thing up and moving the top face back down to line up. Or just just moved the bottom face up by 0.2 units.

Either way, they don't clump and get stuck at the moment.

Git repository: https://bitbucket.org/hiveit/unity-tutorial-coin/src/d6dffd21095e0d30dfaa58120fb130ca41a7ace4/

After some messing around with the shape of the machine…

Open this image in a new tabMachine shape
Machine shape

Now. It's possible to get coins jammed… I will address this in the next part.

Git repository: https://bitbucket.org/hiveit/unity-tutorial-coin/src/28e5f42a6f8c38ff790a4f56cdc1faf55933e4a3/

More posts in this series.