How to Shoot in different Direction ?

OK, i know how to make Gun which spwans a projectile:

var projectile : Rigidbody;
var speed = 20;
function Update()
{
  if( Input.GetButtonDown( "Fire1" ) )
 {
    var instantiatedProjectile : Rigidbody = Instantiate( 
      projectile, transform.position, transform.rotation );
    instantiatedProjectile.velocity =
      transform.TransformDirection( Vector3( 0, 0, speed ) );
    Physics.IgnoreCollision( instantiatedProjectile. collider,
      transform.root.collider );
 }
}

But how could i spawn spread of maybe five projcetiles traveling in a little bit different direction?

And my most Interest: in certain old games, some enemies spawn projectiles circular around themselfes like a wave which travels away from them.

It must not be rigidbodies because they should not fall to the floor.
I know it has something to do with the transform.position and transform.rotation but i can’t figure out the syntax

Any Idea is very welcome

You could use multiple spawn points rotated in a wanted direction or you could create a code to rotate prefabs and their ‘forward’.

Nah, for my example if you would like to shoot a ring-wave with maybe 32 projectile it would be troublesome to setup 32 “guns” which all get trigered once.

If anyone knows i would be interested in how to write that it spwans in one direction and in another

Mabey the transform.rotation can be change by adding some decimal of PI but i don’t know how to code it.

A procedural solution would be very useful for direrent effects.

A rigidbody doesn’t need to fall - you can just turn its gravity off to prevent this from happening. To add a bit of randomness to a projectile’s direction, firstly set it to the orientation of the launcher. Then, add a random value to its Euler angles:-

var variation: float;  // Control how far the projectiles deviate from centre.
proj.transform.direction = launcher.transform.direction;
var ea = proj.eulerAngles;
ea += Random.insideUnitSphere * variation;
proj.eulerAngles = ea;

OK, i got so far:

var projectile : GameObject;

for (var i = 1; i <= 9; i++){

	var instantiatedProjectile : GameObject = Instantiate( projectile, transform.position, transform.rotation );
	instantiatedProjectile.transform.position = Vector3(0, 2, 1.5*i);
	instantiatedProjectile.transform.eulerAngles = Vector3(0, 10*i, 0);
}

pretty strange to me: it does not need to be in any function ?

I use a for-loop to spawn a certain amount and use it to change the rotation degree. But i need them to rotate around the spawners position, not around itself not around the world axis.

Any Tips/Ideas ??? :wink:

Thank you andeeee i just posted same time. Now i will check out your tips :smile:

sucess:

now every instance has a script to drive it forward

var speed : float = 1.0;

function Update ()
{
	transform.Translate(Vector3.forward * Time.deltaTime * speed);
}

An dthe launcher has a script to launch a certain amount which gets equaly rotated and separated
In a circular wave arond the player:

var projectile : GameObject;
var amount : int = 16;


function Update () {
	if( Input.GetButtonUp( "Jump" ) )
	{
		for (var i = 1; i <= amount; i++){

			var instantiatedProjectile : GameObject = Instantiate( projectile, transform.position, transform.rotation );
			instantiatedProjectile.transform.eulerAngles = Vector3(0, 360/amount*i, 0);
		}
	}
}

Or in a certain angle/shotgunlike

var projectile : GameObject;
var amount : int = 3;


function Update () {
	if( Input.GetButtonUp( "Jump" ) )
	{
		for (var i = 0; i <= amount; i++){

			var instantiatedProjectile : GameObject = Instantiate( projectile, transform.position, transform.rotation );
			instantiatedProjectile.transform.eulerAngles = Vector3(0,  (-30)+(60/amount*i)  , 0);
		}
	}
}

Mayb there’s a better way. It would be usefull to start the wave at some distance radius around the player. Not from inside.
And an animated spiral would be nice, we will see :slight_smile:

Admittedly, I did not read everything, but for this bit, I made a slight edit to your last snippet of code:

var projectile : GameObject;
var amount : int = 3;


function Update () {
	if( Input.GetButtonUp( "Jump" ) )
	{
		for (var i = 0; i <= amount; i++){

			var instantiatedProjectile : GameObject = Instantiate( projectile, transform.position + transform.forward*5, transform.rotation );
			instantiatedProjectile.transform.eulerAngles = Vector3(0,  (-30)+(60/amount*i)  , 0);
		}
	}
}

Basically, instead of instantiating the object at your position, you’re instantiating it at 5 steps forward of your position (or whatever you change the 5 to).

You can shoot random direction, within specific radius.

search with noise or perlin

Thank you so much. I have been fighting with this all day in an effort to get a random direction, multiple object spawn drop, and this actually did it for me.

To make the objects rotate around the player just use Transform.RotateAround and set it the players position. Just my two cents.

Setting Rotation via gameObject.transform.rotation.Axis and then applying linear force forward doesn’t work yet. I will pith with it and then post code if I finger it out.