My fast projectile - 3D arrow

Here is my fast projectile “pimped up”:

The blend was free, and downloaded from https://www.turbosquid.com/FullPreview/Index.cfm/ID/1192030.

Once imported I changed the scale of the blend from 1 to 10 to make it more pronounced/visible in game.
image

Edit:
You’ll also want to orientate the arrow so it is facing the player/target.
From Enemy.cs:

private void SpawnProjectile()
    {
        // Create a new instance of the projectile and set it's damage caused
        GameObject newProjectile = Instantiate(projectileToUse, projectileSocket.transform.position, Quaternion.identity);
        Projectile projectileCompoment = newProjectile.GetComponent<Projectile>();
        projectileCompoment.SetDamage(damagePerShot);

        // Gets a vector that points from the player's position to the target's.
        Vector3 heading = (player.transform.position + aimOffset) - newProjectile.transform.position;
        float distance = heading.magnitude;
        Vector3 direction = heading / distance; // This is now the normalized direction.

        // Set the velocity of the new projectile
        float projectileSpeed = projectileCompoment.projectileSpeed;
        newProjectile.GetComponent<Rigidbody>().velocity = direction * projectileSpeed;

        **//Orientate the arrow so it is facing the player**
        newProjectile.GetComponent<Rigidbody>().transform.transform.forward = direction;

    }
2 Likes

This looks good!

A couple of code suggestions:

  • You can simplify in the middle by just saying Vector3 direction = heading.normalized, rather than having to worry about the distance.
  • You can orient the arrow correctly just via newProjectile.transform.forward = directon, you don’t need to use the Rigidbody to do that! :slight_smile:
2 Likes

Hi

Thanks for the suggestions. Makes the code look cleaner. :slight_smile:

1 Like

Privacy & Terms