So my terribleness with Unity continues, its taken me the best past of two and a half hours to make a door open. Yes, really.

Anyway our task today was to produce a detailed blog post that demonstrates a new self taught game or feature made in Unity or C# and since I struggle like I do, its a door opening when you look at it. Nothing fancy and bare arse basic as it gets but it covers what I need to complete this task. We also have to include the following;

  • A video, GIF or image sequence of the self taught uh, thing
  • Links to Unity’s documentation
  • Show some of the code we’ve produced
  • Explain what said code does
  • Make suggestions for development

So, here we go.

In Ant’s powerpoint this morning there were a few examples of what we could do to meet these requirements, one or two in the actual presentation and another couple given in the group discussion. One of these ideas was a door opening and closing automatically and for the sake of simplicity this idea is the one.

door

Instead of making a new scene for this like I originally intended, I decided to incorporate it into my walking sim by having an off shoot room where this door would open.

Capture.PNG
Room and el-doorio in red

I did try to do this myself but predictably I needed help to get this working. I searched around for code to help me get this working and before I knew it I was Googling and finding things that I didn’t really need, things like the link below.

https://forum.unity3d.com/threads/simple-door-c.67674/

A guy in Unity’s forums was wanting to have something similar to what I was looking for, (or I was looking for something similar to his) and I thought that I’d be able to use/adapt it but at 40 odd lines of code this just wasn’t it. After pestering Ant a bit more he’d said that the code I’d need was far more simpler than what was in the link, the bottom line for the below picture to be exact.

code-1
https://docs.unity3d.com.ScriptReference/Vector3.MoveTowards.html

 

I was then told that I’d need something to go with it to make it work with the auspicious clue of “we’ve already covered it”. I did have a thought of Raycasting as I know about the invisible line from the player that makes things happen, so I thought that the opening of the door could be attached or triggered by that. Back through the tutorials I went to find it and came up with the below.

code-3

I did try to integrate this into the *hint, hint* code but rather unexpectedly I struggled with this too – back for help. Talking to Ant I found out that Raycasting wasn’t what he was thinking of but it could be used instead. And this is what I went with. Below is the code I used to make the door open when I approached it.

code-2

After making this work, I see what Ant was getting at when he said ‘that wasn’t what he was thinking of’; instead of the door just opening when I arrive at it like I thought, I have to actually look at the door for it to open. All the way. Moving your viewpoint from the right to the left.

door-slide

It works. The door opens. With help I learned something new.

Now, that just leaves one point to cover from those listed at the top.

  • Make suggestions for development

Learn to code.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s