#Spawn help

1 messages · Page 1 of 1 (latest)

vale pike
#

Oh my bad. It says it in the message. I guess this is a function. So you need to use it like Perpendicular().

#

Just add brackets so that it calls the function

ornate ingot
#

yeah I tried that but still doesn't like it 😦

vale pike
#

Oh wait

#

Second

#

Oh it's a static function. Sorry, I haven't used it before.

#

So

#

Vector2 v = new Vector2 Perpendicular(firePoint.transform.forward.x, firePoint.transform.forward.z); This was almost correct

#

But add a dot before Perpendicular

#

and remove new

#

So we are just calling a stataic function on Vector2

#

It's just a function call, but it is in the Vector2 class

ornate ingot
#

Then it tells me that it doesn't exist haha

vale pike
#

So we do Vector2 v = Vector2.Perpendicular(firePoint.transform.forward.x, firePoint.transform.forward.z);

#

Does that work?

ornate ingot
#

it does not

vale pike
#

??

#

What does it say

#

Oh

ornate ingot
#

I think I know why one sec

#

lol yeah

vale pike
#

When we look at the documentation we see public static Vector2 Perpendicular(Vector2 inDirection);

ornate ingot
#

Vector2 v = Vector2.Perpendicular(firePoint.transform.forward);

vale pike
#

So I guess we need to pass in a vector

#

Okay then we need to do Vector2 v = Vector2.Perpendicular(new Vector2(firePoint.transform.forward.x, firePoint.transform.forward.z));

ornate ingot
#

that works

vale pike
#

yay

#

Sorry, I misread the documentation several times, my bad

ornate ingot
#

ok so now we have a Vector2 that is perpendicular to my firePoint position

#

which as I am understanding it would mean it looks like this

vale pike
#

Uhh, well... It's better to represent v as an arrow.

#

So

warm escarp
#

what are we trying to solve here?

vale pike
#

It is perpendicular to the forward vector. So v should be perpendicular to the direction that the gun is pointing.

#

I draw ugly, but imagine it like this

ornate ingot
vale pike
ornate ingot
warm escarp
vale pike
#

Oh, I guess that is a quicker way of getting the perpendicular vector 😄

warm escarp
#

is that all cases or a unspecified amount of projectiles?

ornate ingot
#

so you can upgrade the projectile type to spawn more projectiles in the game and before I was just spawning them all on top of each other and letting unity physics push them apart but it causes unpredictability

warm escarp
#

so we have 2 "major" cases here: even amount of projectiles meaning nothing goes straight forward and uneven with 1 going forward and the others to the side

ornate ingot
#

that's right yeah

#

which is where var offset = i - (0.5f * projectileAmount); comes into play

warm escarp
#

that would offset the first projectile by -0.5 if projectileamount is 1. doesnt sound right

#

is the problem just the position or also the rotation?

ornate ingot
#

yeah sorry, I add one to the end because it's a for loop

#

no wait

ornate ingot
warm escarp
ornate ingot
#

the total can vary

ornate ingot
#

then it would solve the problem when it is at 1

vale pike
#

If the gap between the bullets is gap, then var range = (i - 1) * gap; and var offset = firePoint.position - range/2 + i * gap;?

#

By range, I mean the length from the leftmost to the rightmost bullet.

#

But I wrote it like an idea, we need to change it for the direction

warm escarp
#

but direction is same idea, have an angle similiar to gap and instead of having the position as a starting point you use the forward and rotate it by a calculated angle dependend on index

ornate ingot
#

one of my main hurdles here is I am unsure how to add to the position

#

how do I add a float to a Vector3

vale pike
#

Isn't is just with +?

ornate ingot
warm escarp
#

just make it a vector3 with the other parts 0

#

at least i assume you want to move on 1 axis?

ornate ingot
#

well the issue is that this happens

#

If that makes any sense at all

warm escarp
#

honestly not really^^

ornate ingot
#

lol when it is rotated it seems like the axis are in world space not local

#

even though the transform is a child of the gun

warm escarp
#

firePos.TransformPoint(Vector3.right * offset);

vale pike
#
var gap = firePoint.right.normalized;
var startingPos = firePoint.position - gap*(bulletsCount-1)/2;

for(int i = 0; i < bulletsCount; i++) {
  var spawnPos = startingPos + i*gap;
}

This should be pretty close to the final code for the position. And it looks pretty clean if it works.

warm escarp
#

oh its a child?

#

then you would just use localPosition

ornate ingot
#

ok so I can just manipulate it on the z-axis in localPosition?

vale pike
#

Oh wait, the bullets are children of the gun?

ornate ingot
#

no the firepoint is a child of the weapon

ornate ingot
#

now they're just spawning in the middle of the world lol

ornate ingot
vale pike
#

Yayy

ornate ingot
#

thanks a ton