Hey guys! I’ve been a pretty long time C# programmer and a moderate amount of time spent with js, but am pretty new to Unity so am hoping for some help, I’m currently attempting to create a sort of multiplayer online arena type of game where players will face off against each other in a FFA format so I’ve got my Plane, PlayerCube and EnemyCubes, HP bars and all that jazz but I’m running into a bit of a problem when it comes to projectiles, here’s the code I tried after my first attempt failed:
function Update () {
// Put this in your update function
if (Input.GetKeyDown(KeyCode.Space)) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Transform;
clone = Instantiate(projectile, transform.position, transform.rotation);
// Add force to the cloned object in the object's forward direction
clone.rigidbody.AddForce(clone.transform.forward * shootForce);
}
}
so when I run this piece of code my PlayerCube is able to shoot cubes but they actually fall through the floor after about half a second and I need them to be able to travel in a straight line (without falling through the ground or accelerating upwards).
I usually like to work through these things on my own but this has had me stumped for about an hour now, I tried doing “clone.rigidbody.velocity” to make the cube come out a tad bit more upwards but then the cube eventually goes flying into the air later in the screen, I want people to be able to hit other players who are on the plane on the other side of the screen so it needs to really travel along the same axis without falling or going higher.
Would really appreciate any help with this! Also I’ve been trying to destroy the projectile cubes when they hit an enemy cube with:
function OnCollisionEnter(theCollision : Collision)
{
if(theCollision.gameObject.tag=="Bullet")
{
Destroy(gameObject);
}
}
but it doesn’t seem to work for me, I have the trigger ticked on the enemy cube but as usual the projectile cubes just pass straight through it and keep travelling.
Thanks in advance for the help!