I’m having trouble instantiating bullets from a changing point in two dimensions. Here’s the situation.
I have a specific point at which a bullet fires from. This point needs to change though, because the bullet increases in size (it’s like a lazer, and thus the bullet gets bigger, but looks as if it’s extending from the gun). Now if my gun is pointed south (negative Y), then there is no issue, as I’m changing the point to go lower based on the size of the lazer. The issue is, as soon as I rotate the gun so it’s not facing directly down, it won’t work. It will still move the lazer down, as opposed to moving the lazer in the direction of the angle it’s pointed in. I’ve been using this function to find the point…
(x,y) = (x + d * sin(a), y + d * cos(a))
the point on the left side is what I want…the d is the size of the lazer object (and the distance I want the point to be from where the lazer was originally created) and a is the angle. This unforutnately doesn’t work. For a better description of this function, I found it here…
Well, you could just put an empty on one side of the laser, attach that empty to the gun barrel, rotate it so that its +z is pointing out of the barrel, and then just scale the z value in order to resize the laser… It’ll automatically adjust with rotation, as it’ll be rotating with the gun.
Wouldn’t there still be an issue with scaling the lazer, as it would be scaled from the midpoint, extending equally in both sides of its Z, and thus the lazer would come out the back end of the gun. This is why the point that I have the lazer sitting at needs to change. Unless, by creating an empty object on the lazer and there is some way to scale in only one direction…but I don’t know how to do that. I would prefer to do this using math, as then I don’t have empty game objects floating around, but if that’s the only way, then I’ll need to know a new way to scale an object.
That didn’t seem to work. If I scale the empty, nothing happens, because it’s empty. There is no mesh to scale. Although scaling the empty AND the lazer made it scale differently, I could still find no solution there. I got some screens to show what’s happening.
Thanks Gargerath and Flynn. After looking at Flynn’s example I was able to figure out a solution. I couldn’t use raycasting because I don’t have a definite point at which to hit…so I created an empty on the gun itself. Then, as the lazer increased in size, I adjusted the local y position of the empty on the gun. This gave me the point I needed.