- Home /
Anyone know why this isn't working?
Ok so heres the deal. Im trying to create a buckshot for a shotgun in my game but when Instantiate the bullets they arent getting an altered rotation like im hoping for. Instead they are all getting no rotation and then end up one on top of the other. Is there any solution to this? Thanks in advance!
for (var i : int = 0 ; i < 8 ; i++){
var rand : int;
rand = Random.Range(-45,45);
var scatter : Quaternion;
scatter = Quaternion.Euler(0,rand,0);
projectile = GameObject.Instantiate(projectilePrefab, startPosition, scatter);
projectile.tag = "Gun";
}
yup im trying to rotate around the y axis because its a top down shooter
I just tested your code and it works, what kind of code do you have in projectilePrefab? try with a simple cylinder.
I was using my projectile as a simple capsule that just moves in a forward motion.
But I figured a way around my problem by just throwing the rotating portion in the moving part of my projectile's script. So its working now.
Thanks everyone for the help!!
Answer by Berenger · Jan 19, 2015 at 04:43 PM
I'm guessing your projectiles aren't moving along their own axis but along their parent's. That's why they don't scatter, while they have a random rotation. Don't forget to uncheck self collision on that layer in the physic settings of the project.
Your answer
Follow this Question
Related Questions
Best way to instantiate lots of objects 0 Answers
C# GameObjects Instantiate Into Each Other Issue 1 Answer
Three Spots For Three Random Objects 1 Answer
How to randomly spawn three non repeating gameobjects from an array? 2 Answers
Rotate "ghost object" then instantiate object with that rotation 1 Answer