Door Segment Animation

Decided to take a look at the door segment scaling issue. The way I hide away the door segments into the frame of the door is by scaling it in the direction of movement.

Here’s what it looks like slowed down:

1

Here it is without scaling:

2

I could just leave it this way without scaling and simply hide the door segments in the surround walls, but the problem is sometimes the surrounding walls are orthogonal to the door, like this:

3

Not to mention the floor…

Anyway, I looked into seeing if I could resolve this by using a shader that makes the parts of the door that protrude transparent.

However, this ended up being much more complicated because of the edge detection shader.

If the object is rendered in the transparent queue, it’s rendered after post-processing, but this means you can see the edges of other objects through parts of the object that are opaque:

4

In the above image, it’s supposed to be stripes of transparency – the white parts should be opaque and you shouldn’t be able to see black edges through it.

But if I render the object not as part of the transparent queue, but before post-processing, the outline of the object itself gets drawn. Notice that an edge is drawn along the part that is supposed to be transparent:

5
Obviously, I don’t want to see the outline of the door segment that’s protruding.

Another approach that I thought would work would be the replace the door segment with a single box with a texture applied on top, and then offset the texture based on how much scaling was done.

However, that had the same issue with the edges. The door segment with the texture (float in front) looks very different than the actual door:

6

Some people on twitter suggested simply modeling and animating the door in a 3D software, and have parts that nest into each other as the door goes into the frame. This would work.

However, I thought about it some more, and I don’t think it’s really an issue I need to worry about. The scaling seemed very obvious in the gifs I posted mostly because time was slowed down quite a bit. In the game, the door opening happens in 0.3 seconds. It’s literally a fraction of a second, and given that players are usually standing some distance away when the door opens (because they’re pressing a button or putting a box on a switch), the scaling effect would be hardly noticeable.

You can see the door in action in the gif below, in which I demonstrate cubefruit regrow and destruction (that happens behind the camera), working with the traveling light path and the door switch in a perfect loop:

7

The door opening is so quick I don’t think it’s anything to worry about at least for now. If it really proves to be a problem later on, I’ll just get a 3D artist to animate it with the suggestion above.

 

 

 

Fruit Growing On Tree Continued

Worked on both growing and shrinking of the cubes today.

shrink-on-ground-grow-on-tree

Most of the day was spent trying to get the coroutine order right, and to have the cube that’s not on the tree be destroyed as soon as you pick the new cube off the tree (so that’s there’s only ever one cube at a time).

Eventually got it so that when you pick a cube off the tree, a new one grows in its place:

fruit-picking-and-growing

Lots of bugs still, and it’s going to be a while before I get everything right.

 

 

Fruit Growing on Tree Basics

Got the basics of fruit growing on tree working.

fruit-growing-on-tree

In the above gif, the animation looks pretty dead. It’s just a linear growth rate.

I then switched to using an animation curve to control the growth rate, and made it so the box actually is larger than normal at a certain point to add some juiciness to the animation.

Found this really funny glitch while playing around:

fruit-growing-glitch

Anyway, you can pick the box off of the tree and then use that box to open a door:

fruit-growing-on-tree-door-opening

It was a really cool moment when I finally saw this. I’ve had this idea in my head for so long…. Since Tokyo Game Show in October I believe. To finally see it in action felt very weird, but incredibly satisfying.
Like I knew exactly what to expect since I wrote it, but to actually see something with my eyes that I had been picturing in my head for so long… I couldn’t stop laughing.

 

 

 

 

Traveling Light on Switch and Doors!

Got the light on the line to work together with the switch:

box_traveling_light

I think it works better for the entire line to go off when the box is removed, instead of having the light slowly retreat, as that would look pretty weird just to have the light on but not the box there. Also feels more snappy that way.

Also worked on door animation: door-opening

I think I’d like to draw up some more designs of doors. I like the way this opens (feels very equal on all sides, which is necessary for the mechanic), but I wonder if the actual design can be improved.

Calling the door animation from script was a bit more tricky as Unity 5 has changed the API for animation, and it’s quite confusing coming from Unity 4.

Basically, it seems like one has to use animator now instead of animation component, and it’s animation states instead of animation clips.

Here’s how the script looked to get the call the animation from within a script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using UnityEngine;
using System.Collections;public class DoorController : MonoBehaviour {
void Start () {

}

// Update is called once per frame
void Update () {

if (Input.GetKeyDown(KeyCode.T)) {

GetComponent<Animator>().Play("DoorOpen");
}

if (Input.GetKeyDown(KeyCode.Y)) {

GetComponent<Animator>().Play("DoorClose");
}

}
}

Once that was done, it was just a matter of connecting the door to the switch: switch-door-light-almost

It feels quite satisfying, but I’m going to make it so that the door doesn’t open until the light travels across the path and hits it. Right now the door opens right when the box gets placed on the square, and I think it feels a little bit off.