Recap: Turret
Part of the Physics and Gameplay section of Coddy's Unity journey. Lesson 44 of 63.
Challenge
MediumWrite the turret's script. The tank drives with the arrows (its script is ready), and the turret, a little taller than the tank, keeps it in its sights:
- It turns toward the tank at
turnSpeed(90) degrees per second, never faster, and around its y axis only: it never tips up or down. - Space fires a shell (
shellPrefab). The shell starts 1 unit in front of the turret's center and 0.5 above it, in the turret's own directions, and faces the way the turret faces (the ready-made Shell script flies it forward).
Press Play, drive around and fire, then Check.
Try it yourself
using UnityEngine;
public class Turret : MonoBehaviour
{
public Transform tank;
public GameObject shellPrefab;
public float turnSpeed = 90f;
void Update()
{
}
}
All lessons in Physics and Gameplay
1Rigidbody
Gravity and MassPush with AddForceJump with an ImpulseFixedUpdate for PhysicsVelocityKinematic BodiesRecap: Launch Pad2Collisions
OnCollisionEnterWhat Did I Hit?Break on ImpactStanding on the GroundBounce and FrictionCollider ShapesRecap: Breakable Wall