GameDev – A collection of things that don't really matter https://www.riptor.com Mostly useless content from the Pacific Northwest Tue, 25 May 2021 15:44:21 +0000 en-US hourly 1 https://wordpress.org/?v=6.9 Debuggery https://www.riptor.com/2021/05/29/debuggery/ Sat, 29 May 2021 15:25:00 +0000 https://www.riptor.com/?p=185 Continue reading Debuggery ]]> I was having a terrible time finding if a sword slash hit a barrel or not… which, it clearly did not because the barrel did not trigger a collision. After numerous attempts to figure out what was going on, I started on a path to debug … well … the path the collider was on! So I wrote a script.

I’m using box colliders since everything I’m doing does not require precision. This makes it easy to script up something to highlight the path my colliders have been on.

The code is below. I tossed an MIT license on it so you can use it however you like. You can add it to any game object that has a box collider or add it to an empty object in your scene and reference a box collider. You could even adapt the script to use some other collider if you like.

/**
 * MIT License
 *
 * Copyright (c) 2021 Josiah Olivieri
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

/**
 *
 * this is used to debug the path a box collider proceeds on as the game is played. i am hoping it 
 * proves useful in debugging whether a target is hit or not in combat.
 */
public class DebugColliderPath : MonoBehaviour {

    public bool debugTrail = false;

    public BoxCollider boxCollider;
    public float captureRate = 0.5f;
    public int maxPoints = 10;
    public bool connected = false;
    public Color trailColor = new Color( 1.0f, 0.75f, 0.0f );

    private List<List<Vector3>> debugPath = new List<List<Vector3>>();
    private float lastTimeDebugTrail;

    void Start() {
        if (debugTrail && boxCollider == null) {
            boxCollider = GetComponent<BoxCollider>();
        }
    }

    void FixedUpdate() {
        if (debugTrail) {
            if ( boxCollider == null || boxCollider.gameObject == null ) {
                debugTrail = false;
                return;
            }

            if (Time.time - lastTimeDebugTrail < captureRate)
                return;

            lastTimeDebugTrail = Time.time;

            Vector3 center = boxCollider.center;
            Vector3 boxSize = boxCollider.size / 2.0f;

            List<Vector3> points = new List<Vector3>();
            for (int i = 0; i < 8; i++) {
                Vector3 extents = boxSize;

                extents.Scale( new Vector3( ( i & 1 ) == 0 ? 1 : -1, ( i & 2 ) == 0 ? 1 : -1, ( i & 4 ) == 0 ? 1 : -1 ) );

                Vector3 localPos = center + extents;
                Vector3 globalPos = boxCollider.transform.TransformPoint( localPos );

                points.Add( globalPos );
            }

            debugPath.Add( points );

            if (debugPath.Count > maxPoints)
                debugPath.RemoveAt( 0 );
        }
    }

#if UNITY_EDITOR
    void OnDrawGizmos() {

        if ( debugTrail ) {
            if (boxCollider == null || boxCollider.gameObject == null) {
                debugTrail = false;
                return;
            }

            GUIStyle style = new GUIStyle();
            style.richText = true;
            style.fontSize = 12;

            Color trails = new Color(trailColor.r, trailColor.g, trailColor.b, 0.0f );
            
            float alpha = 0.0f;
            float inc = 1.0f / (float)maxPoints;
            int n = 0;
            if ( debugPath.Count < 1 )
                return;

            var lastPoints = debugPath[0];
            foreach (var points in debugPath) {
                Gizmos.color = trails;

                for ( int i=0; i<7; i++ ) {
                    for ( int j=i+1; j<8; j++ ) {
                        Gizmos.DrawLine( points[i], points[j] );
                    }
                }

                if ( connected ) {
                    Gizmos.color = new Color( trails.b, trails.r, trails.g, alpha );
                    for ( int i=0; i<7; i++ ) {
                        Gizmos.DrawLine( points[i], lastPoints[i] );
                    }
                }
                
                UnityEditor.Handles.Label( points[0], "<color=white>p" + n + "</color>", style );
                n++;

                alpha = alpha + inc; 
                if ( alpha > 1.0f ) alpha = 1.0f;
                trails.a = alpha;
                lastPoints = points;
            }
        }
    }
#endif
}

That’s all for this week. This little example was fun to work on but it also proved useful. (I found that the animation was key-framed to the side of the barrel and past the barrel… so I turned on animate physics and it seems like things… barrels… are breaking correctly now!)

]]>
Routines https://www.riptor.com/2021/05/23/routines/ Sun, 23 May 2021 18:00:00 +0000 https://www.riptor.com/?p=182 Continue reading Routines ]]> I really don’t have anything useful to say.

Our country is overflowing with distrust, hate, and inequity.

Our world is plagued and forever changed.

Humans need to be willing to be influenced by new facts and perspectives.

I want to add some writing time to my daily or weekly routine. With all that is going on outside of my tiny pocket of the world I will need to find something that I care to share with others. I will likely put some effort into a side project and share the progress here. It’s not anything that matters in the broader spectrum of the current events, but I will share regardless.

I had a project awhile back (2017?) that I started… I made the art (2d vector sprites, animated with Spine) and built in Unity. I recently took all the 2d code and ported it to 3d to make a side-scrolling dungeon crawling adventure that uses 3d scenes and models with a 2d feel. I’ll keep tinkering with this project and share updates from time to time.

]]>
Day / Night cycle https://www.riptor.com/2018/04/29/day-night-cycle/ Mon, 30 Apr 2018 04:38:34 +0000 https://www.riptor.com/?p=145 Continue reading Day / Night cycle ]]> I just managed to swing a day to night cycle in Unity and it only took me … 30 minutes! and it’s beautiful to boot.  I’m using some assets from Synty Studios which turned me on to an awesome, and totally free, post processing stack that looks great in the day to night cycle.

  1. Basic Setup

a. Find the SM_Generic_SkyDome in the POLYGON_Renderbox assets. You’ll put this in your scene and it will be hooked up later to the script that manages the transitions.

b. Add a directional light to the scene. It doesn’t really matter what color you use, we’ll set those up later in our script.

c. Run the game and make sure everything looks nifty.

2. New Script

Create a new script named DayNightTransitionManager and attach it to an empty object in the scene.

    public class DayNightTransitionManager : MonoBehaviour {

        public Light light;

        public List<Material> materials;
        public List<Color> colors;
        public float timeBetweenCycles = 60.0f;
        public float transitionTime = 20.0f;

        public MeshRenderer rend;

        private float lastCycle = 0.0f;
        private int pointer = 0;
        private int next = 1;
        private int max = 0;

        private bool inTransition = false;

        void Start() {
            lastCycle = Time.time;
            max = materials.Count;

            rend.material = materials[ 0 ];
            light.color = colors[ 0 ];
        }

        void Update() {

            if ( !inTransition ) {
                if ( Time.time - lastCycle > timeBetweenCycles ) {
                    inTransition = true;
                    lastCycle = Time.time;

                    Debug.Log( "DayNight moving to transition phase" );
                }
            } else {

                float amount = Mathf.Clamp( ( Time.time - lastCycle ) / transitionTime, 0.0f, 1.0f );
                rend.material.Lerp( materials[ pointer ], materials[ next ], amount );
                light.color = Color.Lerp( colors[ pointer ], colors[ next ], amount );

                if ( Time.time - lastCycle > transitionTime ) {
                    inTransition = false;
                    lastCycle = Time.time;

                    rend.material = materials[ next ];
                    light.color = colors[ next ];

                    next = ( next + 1 ) % max;
                    pointer = ( pointer + 1 ) % max;

                    Debug.Log( "DayNight moving out of transition phase" );
                }
            }

        }
    
    }

 

3. Connecting it all up

a. Drag your Directional Light into the Light field in the inspector.

b. Drag the SkyDome object into the Rend field in the inspector.

c. I set the materials and colors sizes to 4, and added the following elements to materials:

Skydome_Day
Skydome_Sunset
Skydome_Night
Skydome_EarlyMorning

d. I used the following colors for each stage:

#FFF4D6FF
#FCC88500
#35388000
#FA240000

4. Enjoy!

]]>
Slow progress https://www.riptor.com/2017/11/28/slow-progress/ Tue, 28 Nov 2017 15:42:25 +0000 http://www.riptor.com/?p=133 Continue reading Slow progress ]]> I finally started to look at Node.js. I’ve never truly enjoyed JavaScript but the new spec makes the language feel pretty modern and there are plenty of editors out there that make editing a breeze.

I decided to stand up a simple server with a NoSQL solution behind it. This was very simple. I used tutorials from the Node.js site as well as a few from w3schools. Before I knew it I was sending my metric data from my dungeon platform game to a server that captured the metrics and shoved ’em in a collection.

I still need to do something with the data but I’m making progress again. The next step is to handle some auth (or a simple challenge for the client / server) and some input validation to ensure what I’m reading is meant for the service. I also haven’t quite worked out how to gather the data out of mongo and make it useful but there’s always something else to work on.

]]>
Zero percent days https://www.riptor.com/2017/06/13/zero-percent-days/ Tue, 13 Jun 2017 15:19:15 +0000 http://www.riptor.com/?p=121 Continue reading Zero percent days ]]> After looking into Unity’s 9-slice sprites I haven’t spent a lot of time (read: zero) working on my project. Turns out the 9-slice sprites really suck for grid alignment and tilemaps.

I’m moving over to use Super Tilemap Editor instead. It has some nice editing tools that I hope will be useful in designing rooms for the dungeons. Today I’m breaking my zero percent streak.

]]>
Lacking Updates Again https://www.riptor.com/2017/04/17/lacking-updates-again/ Mon, 17 Apr 2017 15:06:18 +0000 http://www.riptor.com/?p=114 Continue reading Lacking Updates Again ]]> Can’t say much other than life has been fairly busy. Our kitchen remodel is finally done. It only took 3+ months of actual construction but that was after 6 months of waiting for them to get started. Now that it is done I expect to send out some invites to friends in the area for a potluck!

Game development has been slow but I have been working step by step on http://www.averagejoesoftware.com/. I have automated builds published to the site (that I’m not publicly sharing yet) and a link to a Trello bug board. I haven’t exposed the feature board yet but that’s setup too.

My son and I have been working on his Capsule Dragons game. I found a couple of fantastic resources as we’ve been trying to get same-screen multiplayer working. First, as far as Unity input goes it’s rubbish, so there’s this page about how to get multiple controllers working. And then I modified this one slightly to handle an expanding camera that tracks multiple targets. Overall it’s been a fun-filled and productive Easter weekend.

Aside from all that I’ve been working on telemetry and experimentation for my day job on OneDrive for iOS. We’re hiring if you know anyone that might want a job working with a fantastic team.

]]>
What’s left? https://www.riptor.com/2016/11/16/whats-left/ Wed, 16 Nov 2016 16:10:04 +0000 http://www.riptor.com/?p=108 Continue reading What’s left? ]]> I’m at that point in my game development process where I have a limited number of things that must be done before I can release 0.1. This is sort of a make-it-or-break-it point in my project.

Here’s what’s on the list…

Win Condition

Each game should have a condition that allows the player to “win”. In my game this would be the completion of the dungeon or some scenario (such as destroying all portals). This should be easy to do.

Title Screen

I still don’t have a title screen or a title for my game. This should be easy enough to add.

Game Over Screen

It would be nice to know when you’ve utterly failed and have some options for what to do next in the game. This screen isn’t that difficult.

Analytics

What you say!? Capturing data about the user so I can nefariously use it against them? Oh ho ho ho ho, how fiendish of me you say? Not really. I would like to know if there’s a particular jump that’s not working well or if a run through takes too long or not enough time. This will allow me to improve the mechanics as I work towards a 1.0 release.

Sound… and Music

Here’s the real hard bit. I’m horrible at writing, composing, looping, or trying to build music. Everything else I can fake pretty well. If you know of any good sound libraries or music enthusiasts that want to work for beer… please let me know!

I have a few nice to haves as well but I’ll save those for another time.

So why write all this down? Two reasons:

  • I need a place where I can reflect on the things I think I need to do and making it public helps create a forcing function to actually completing them.
  • I want to be in the habit of writing updates so I can communicate with my player base more frequently. Right now my player base is all of 2 people (thanks guys!) but I hope to expand that when 0.1 is ready.
]]>
Action Sequence https://www.riptor.com/2016/02/25/action-sequence/ Thu, 25 Feb 2016 19:00:35 +0000 http://www.riptor.com/?p=60 Continue reading Action Sequence ]]> I’ve been working on a simple platforming dungeon crawler. I’m not a super game developer or an amazing artist but it’s not stopping me from building something I want to play.

In my dungeon crawler I want to do more than just whack skeletons with a big ol’ axe. I want to play with multiple people on the screen, cast spells that help my allies and hurt my foes, and I want the experience to be fun.

I put together a set of scripts that handle a sequence of actions as directed by a player. Here’s a video that shows it working.

My plan is to reuse the pattern to produce other spells, abilities, and what not. I still have plenty to do with it but it’s a work in progress.

]]>
Parallax Scrolling https://www.riptor.com/2016/02/24/parallax-scrolling/ Wed, 24 Feb 2016 19:36:26 +0000 http://www.riptor.com/?p=58 I found a fantastic post here for building a parallax background in Unity.

I had a parallax background done in 5 minutes. The hardest part was figuring out if I wanted to use a plane with a texture material or something else. (I went with a plane for this one).

 

 

]]>