Issue making custom projectile

Hello Again

After the 'Using The Trail Renderer Component’ video I tried to replace the Fast Projectile RollberBall object with an Arrow model I downloaded from the asset store.

After I added the required components to the Arrow Object and put it on the projectile slot it began behaving funny. The enemy shots the projectile but the rotation of the arrow is off, it is vertical. When I drop the arrow prefab into the scene the object is horizontal like I want it to be but during play the rotation changes.

During runtime I tried playing with the options on the Arrow’s rigid-body, like constraining rotation, but none of these seemed to have an effect on my projectile. I recorded a video of the issue and posted screenshots of my Arrow’s components.

DropBox link: https://www.dropbox.com/s/evblici68i1s9sp/ArrowIssue.mp4?dl=0

Hi @Crede.Pendrel,

Take a look at Enemy.cs and the FireProjectile() method.

I created a new projectile, just a cube which I then scaled to make it look like an arrow, and set it up as per the other projectiles.

I experienced the same behaviour as you, even though the rotation was set on the prefab.

I checked where the prefab was being instantiated (the above method) and in here I made the following change;

        private void FireProjectile()
        {
            // GameObject newProjectile = Instantiate(projectileToUse, projectileSocket.transform.position, Quaternion.identity);
			GameObject newProjectile = Instantiate(projectileToUse, projectileSocket.transform);
            Projectile projectileComponent = newProjectile.GetComponent<Projectile>();
            projectileComponent.SetDamage(damagePerShot);
            projectileComponent.SetShooter(gameObject);

            Vector3 unitVectorToPlayer = ((player.transform.position + aimOffset) - projectileSocket.transform.position).normalized;

            float projectileSpeed = projectileComponent.GetProjectileLaunchSpeed();
            newProjectile.GetComponent<Rigidbody>().velocity = unitVectorToPlayer * projectileSpeed;
        }

Note, the Quaternion.identity - quote “This quaternion corresponds to “no rotation” - the object is perfectly aligned with the world or parent axes.”

I then changed the arrow prefab to have a rotation of 90 on the Z axis and I got a result closer to what you were requiring.

Note, this is a bit of a quick hack to get an arrow to fly closer to how you would expect, I didn’t invest and significant time in this with regards to adverse effects for other project types.

If you watch the video clip you can see that whilst the arrow is now horizontal and not vertical, it is still not pointing towards the enemy. At this stage in the course, we have not yet set the enemy models to actually face our hero, nor is there a lot of work involved in firing the projectiles.

This will most likely get you a little closer and hopefully you can refine from here :slight_smile:

@Rob

Thank you very much for your detailed and well articulated response. When I made the changes you suggested my project actually started acting more buggy. The first couple arrows came our horizontal but they started spraying out in all directions. As of now, the arrows are still hitting and wounding the hero, its just the visual thats off.

Obliviously this will be going on the TODO list for now, and ill try to tinker with it when I have a better idea how to tackle it.

Thanks again Rob! Top Notch.

lol… happy to help! :smiley:

Sorry, about that… of course our projects may differ.

I haven’t strayed from the course yet, so I have nothing in there to rotate the enemies to rotate in the direction of the player, as such, tennis balls fly out of the back of their heads.

I like your scene by the way, looks really good :slight_smile:

Don’t worry Rob, its all good.

I really like my scene too! I am however experiencing some inner turmoil after watching the lecture about the billboard grass. It looked so good and with my scene of all meshes I couldn’t add the same effect. Today I want to try creating a regular Unity terrain. I don’t know if its going to work with the existing Art Design Document but I suppose I can always more than one version of the document/game.

Privacy & Terms