Chip Defense (My Realm Rush game)

Here’s what I came up with for this project. I couldn’t really get into it with the resources I found in the Unity Asset store, so I decided to create my own voxel models with Magica Voxel. (The free course here on GameDev.tv was very helpful!)

In addition to the features we walked through in the course, I added a few of my own:

  • Turrets lock onto a target and follow it until the target is out of range or destroyed
  • Smoothed out the turret animation
  • You can click on the towers to destroy them and recover half their cost
  • Background music and SFX

I used some additional assets to make this project.

4 Likes

Congratulations on your game! This is such a cool concept! :partying_face::partying_face:

1 Like

I really like your turret animation. How did you smooth out the turret rotations?

@GameProgrammer2k Thanks. Here’s the code I used in my TargetLocator script to aim the weapon. It uses Quaternion.LookRotation(). I found an example of this via Google. I can’t remember where but there’s also an explanation of how to do something similar in the Zombie Runner course here.

    void AimWeapon()
    {
        if (target == null) { return; }
        targetDistance = Vector3.Distance(transform.position, target.position);

        Vector3 direction = target.position - weapon.position;
        Quaternion targetRotation = Quaternion.LookRotation(direction);
        float rotationAmmount = turnSpeed * Time.deltaTime; 
        weapon.transform.rotation = Quaternion.RotateTowards(weapon.rotation, targetRotation, rotationAmmount);

        if (targetDistance <= range && lockedOn == false)
        {
            Attack(true);
            lockedOn = true;
            target.GetComponent<EnemyHealth>().towers.Add(gameObject); 
            lockedTarget = target.GetComponent<Enemy>();
        }
 
        else if (enemyDestroyed || targetDistance > range)
        {
            Attack(false);
            lockedOn = false;
            enemyDestroyed = false;
        }

        if (targetDistance > range) {
            {
                target.GetComponent<EnemyHealth>().towers.Remove(gameObject);
            }
        }
    } 

Note that there is some additional script in there for how I locked on to targets as well, so not all lines are applicable to just turning.

Hope that helps.

Thanks! The RotateTowards() was the piece I was missing. I didn’t know that existed so I didn’t know to search for it. I should have guessed unity would have some easy way to do that. The tower movement looks great now.

Quaternions make my head hurt a bit. I kept trying to get some kind of percentage between the 2 Quaternions, which didn’t work.

Now I just need to make my towers also not fire until they’re almost facing the enemy. It looks like that can be done with Raycast(), which is covered in the Zombie Runner course.

Glad it helped. Yeah I still don’t have Quaternions quite figured out but it works :smile: Good luck with your project!

Privacy & Terms