Tag Archives: Unity

Updates For Spider Swarm

Play!

By: Ben Johnson

Description

In preparation for creating my first video game trailer, I have updated some of the visual aspects for Spider Swarm to hopefully produce a better video without lying about the gameplay. While I am sure it would  have been much easier to just take the environment models and use Blender to make a full CGI trailer like many games do now a days, it felt a lot like lying to me if the footage show was not something you could actually expect to happen in gameplay. As a gamer I personally hate when games try to pull this cheap trick of not showing you what the real game is and instead just glossing it over with something mildly related. Hopefully with these updates I will be able to create a fun an interesting demo trailer to post here in the coming weeks. Thankfully most of the visual changes we possible due to the animations that came pre-made for the fantasy spider model in the Unity asset store.

 

Change Log

  • Added a basic muzzle flash for the rifle.
  • When spawning enemies burst out of the ground.
  • When dying enemies sink back into the ground after their death animation is finished.
  • Enemies now have hit animations (2 unique ones) and hit sound effects (2 unique ones).
  • Enemies now have an additional death animation and more death sound effects.
  • Enemies now have an additional attack animation and more attack sound effects.
  • Rest period now has a count down timer to keep player ready for incoming spiders.
  • Spiders are a little less likely to climb on top of each other in large numbers.
  • Spiders now use a third spawn zone.
  • Spiders now spawn in smaller groups rather than all at once per wave.
  • Added small ammo pack in the beginning of the scene.
  • Axe now uses a sound effect when swung.
  • Attacks no longer loop instantly, they now wait for their animation/sound to finish before looping.
  • Added different music for both battling and resting. Note that the battling music is from the video game Pain Killer and is not mine.
  • Lowered player max hp to 200 as the rifle makes things too easy for 500.
  • Lowered ammo boost from ammo boxes to only grant 15 shots.

 

Controls

  • W, A, S, D – Move player.
  • Q – Switch weapons
  • Mouse – Aim/Look
  • Left Mouse Button – Attack
  • Space – Jump

Swarm

Play!

By: Ben Johnson

Description

Swarm is a simple game where a player is trapped in a graveyard with nothing more than a gun, an axe, and an endless horde of spiders to fight. In the game you start with no ammo and must fight with your axe until the spiders begin dropping ammo packs, but beware as the spiders will fight back if you get to close to them. While this game may seem simple, it was designed as a test for using the built in Unity FPS controller with a basic weapon system. Using the scripts created for this program it would be relatively simple to create an FPS game with multiple weapons, ammo types, and abilities. All assets used in this game are not my property and were taken from the Unity store. You can find them all under the free assets sections.

Known Bugs

  • In order to pick up both weapons you must first pick up one, hit q to switch to the empty slot, and the you can pick up the other.
  • Gun is missing a muzzle flash. While it would not be hard to add one, I’ve moved on from this project as it was just a test and I’d rather not continue tweaking it unless it is a major fix.

Controls

  • W, A, S, D – Move player.
  • Q – Switch weapons
  • Mouse – Aim/Look
  • Left Mouse Button – Attack
  • Space – Jump

Images

Camera Relative Movement

Description

In many older 3D games (such as Mario 64 and the Legend of Zelda: Ocarina of Time)  for consoles like the N64 and Playstation games used a simple movement scheme called camera relative movement. In camera relative movement the player moves according to where the camera is. For example if the player holds the left button, the players avatar will run to the left in a circle around the camera. Using the two C# scripts at the bottom of this post you can do the same in just about any Unity project so long as you assign the proper variables and create the scripts necessary to interact with the player. An example of these scripts in action can be found at: Adventure Game Test.

Code

CameraRelativeMovement.cs

using UnityEngine;
using System.Collections;

public class CameraRelativeMovement : MonoBehaviour
{
    public Transform targetCamera;
    public Transform lookAtTarget;
    public Transform watchTarget;        
    public float forwardDirection;
    public float sideDirection;
    public float maxSpeed = 10.0f;        

    private CharacterMovement movement;
    private Transform myTransform;

    // Use this for initialization
    void Awake()
    {
        myTransform = transform;
        movement = GetComponent<CharacterMovement>();
    }

    // Update is called once per frame
    void Update()
    {
        Vector2 input = new Vector2(sideDirection, forwardDirection);
        float speedScale = input.magnitude;

        if (speedScale > 1.0f)
        {
            speedScale = 1.0f;
        }

        Vector3 moveRequest = GetMovementRequest(input);

        if (lookAtTarget != null)
        {
             Vector3 direction = lookAtTarget.position - transform.position;
             direction.y = 0.0f;
             movement.RequestRotateTowards(direction.normalized);
        }
        else
        {
             movement.RequestRotateTowards(moveRequest.normalized);
        }

        if (watchTarget != null)
        {
            movement.RequestWatch(watchTarget.position);
        }
        else
        {
            movement.RequestWatch();
        }

        movement.RequestMovement(moveRequest, speedScale * maxSpeed);
    }

    private Vector3 GetMovementRequest(Vector2 input)
    {
        Vector3 forward = myTransform.position - targetCamera.position;
        Vector3 right = Vector3.Cross(myTransform.up, forward);
        Vector3 moveRequest = input.y * forward + input.x * right;
        moveRequest.y = 0;
        return moveRequest;
    }
}

CameraMovement.cs

using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour
{
    public float movementDamping = 5.0f;
    public float rotationDamping = 5.0f;

    private Transform myTransform;

    // Use this for initialization
    void Awake()
    {
        myTransform = transform;
    }

    public void SpringToTarget(Transform target, float preferredDistance, float preferredHeight)
    {
        float distance = Vector2.Distance(new Vector2(target.position.x, target.position.z),
                                          new Vector2(myTransform.position.x, myTransform.position.z));
        Vector3 moveDirection = target.position - myTransform.position;
        moveDirection.y = 0.0f;
        moveDirection = moveDirection.normalized * (distance - preferredDistance) + myTransform.position;
        moveDirection.y = target.position.y + preferredHeight;
        MoveToPosition(target.position, moveDirection);
    }

    public void SpringToTargetWithConstantOffset(Transform target, float preferredDistance, float preferredHeight)
    {
        float distance = Vector2.Distance(new Vector2(target.position.x, target.position.z),
                                          new Vector2(myTransform.position.x, myTransform.position.z));
        float z = Mathf.Sin(myTransform.rotation.y) * distance;
        float x = Mathf.Cos(myTransform.rotation.y) * distance;

        Vector3 moveDirection = new Vector3(x, 0, z);
        moveDirection.y = 0.0f;
        moveDirection = target.position - moveDirection.normalized * preferredDistance;
        moveDirection.y = target.position.y + preferredHeight;
        MoveToPosition(target.position, moveDirection);
    }

    // returns true if camera is pretty much behind the target
    public bool MoveBehindTarget(Transform target, float preferredDistance, float preferredHeight)
    {
        Vector3 moveDirection = target.forward;
        moveDirection.y = 0;
        moveDirection = moveDirection.normalized * -preferredDistance + target.position;
        moveDirection.y += preferredHeight;
        MoveToPosition(target.position, moveDirection);
        return (myTransform.position - moveDirection).magnitude < 0.5f;
    }

    public void RotateAroundPoint(Vector3 target, float rotation)
    {
        Vector3 forward = myTransform.position - target;
        Vector3 right = Vector3.Cross(myTransform.up, forward);
        float distance = Vector3.Distance(myTransform.position, target);

        Vector3 targetPosition = forward + right * rotation;
        targetPosition = targetPosition.normalized * distance;
        targetPosition.y = myTransform.position.y;
        targetPosition.x += target.x;
        targetPosition.z += target.z;
        MoveToPosition(target, targetPosition);
    }

    public void LookAtTarget(Vector3 direction)
    {
        transform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(direction), rotationDamping * Time.deltaTime);
    }

    private void MoveToPosition(Vector3 lookAtTarget, Vector3 targetPosition)
    {
        Vector3 direction = (targetPosition - lookAtTarget).normalized;
        float distance = Vector3.Distance(lookAtTarget, targetPosition);

        RaycastHit hit;
        if (Physics.Raycast(lookAtTarget, direction, out hit, distance) &&
            (hit.collider.CompareTag("Wall") || hit.collider.CompareTag("Door")))
        {
            myTransform.position = Vector3.Lerp(myTransform.position, hit.point, movementDamping * Time.deltaTime);
        }
        else
        {
            myTransform.position = Vector3.Lerp(myTransform.position, targetPosition, movementDamping * Time.deltaTime);
        }
    }
}

Adventure Game Test

Play!

by: Ben Johnson

Description

This is an attempt to create a simple adventure game that works similarly to the 3D Legend of Zelda games. In this adventure you start off in a prison with a single NPC who allows you to leave, you then later find two more NPCs with a simple quest, and finally you battle your way past a guard and the prison boss. This game features several camera systems including a standard chase camera, a targeting camera for combat, and a first person camera to line up jumps and get a better view of the world. In this game all models are made of simple geometry to avoid any of the quirks with animation and allowing me to focus on recreating the basic game and camera system of The Legend of Zelda.

Controls

  • W and S – Move Character Vertically
  • A and D – Rotate Character Left and Right
  • Mouse/Left Control – Attack
  • Space – Action (Talk, Roll, Open Door)
  • Q – Use Targeting System
  • I and K – Look Up or Down (enables first person look camera until player hits Q to cancel)

Images

Power Pong

Play!

by: Ben Johnson

Description

As a beginning game designer it seems that creating a simple game of Pong is required as a right of passage. In this version of Pong you will battle against a simple AI opponent who will return any shot it can. To help you in your fight against this nefarious AI you can use various power ups that you collect by hitting the ball at them. Powers include the Grow box which widens your paddle, Tea Time which gives stops the ball and allows you to quick move in front of it in emergencies, and the dreaded Orange Shower which fills the screen with distracting oranges. Please note that there is no end to this game, you simply play until you have had enough.

Controls

  • W and S: Moves the paddle up and down respectively.
  • Q: Activate power up.

Images