I created a new material and named it fx_lazer_orange. And I added a texture that was inside the asset pack on it. And now i have a material for the shot.
I then made an empty game object and called it "Bolt" and as a child of this object I made a Quad and called it "VFX".
I added the texture on top of the quad but there was this black around it. So to fix this I had to set the shader to Paticles > Additive. And now the bullet is bright and has a nice transparent background.
My next step was to add a collider on it so that when it hits something it would disappear. So I got rid of the current mesh renderer that was on it and I put a Capsule Collider on it. I modified its height and length and now the capsule wraps around the bullet.
(The green cylinder that's inside the bullet)
After this I had to make the code the makes it move. So I made a new script and called it 'mover'
And the code to make it have a constant motion was pretty simple.
It took one line of code:
rb.velocity = transform.forward * speed;
So the velocity is the transform with forward motion on the z axis multiplied by speed.
Now that was pretty simple and now I have a constant motion as soon as it spawn. But how do I make it shoot from the front of the ship?
What I had to do was make an empty game object and call it "Shot Spawn" and place is as a child of the player so that the shot spawn position is always relative to the position of the player ship.
I then proceeded to edit the playercontroller script.
I made a few new variables called myTime, nextFire and fireRate. In the update function I made myTime + Time.deltaTime and made it so that I can only fire if the myTime is larger than the nextFire (which was set 0.5 seconds). So I could only fire every 0.5 seconds. And I made an if statement and made the shot instantiate (clone) at the position of Shot Spawn. Very simple code that works.
This is how it turned out.
No comments:
Post a Comment