I'm developing a demo of a 3D Space Ship game concept in Unity, just for learning purposes.
I have a cube representing my space ship in the scene, and a laser prefab that is instantiated at the 2 sides of the space ship any time the user presses the spacebar, i use this C# code (placed in the script attached to the space ship, just a cube right now) to calculate the position of the lasers and instantiate them:
Vector3 laser1Position =
this.transform.position + this.transform.forward + this.transform.right;
Vector3 laser2Position =
this.transform.position + this.transform.forward - this.transform.right;
Instantiate (laser, laser1Position, this.transform.rotation);
Instantiate (laser, laser2Position, this.transform.rotation);
At this point, everything worked perfect, and the lasers are instantiated correctly at the sides of the cube, exactly at the middle of the 2 sides.
The problem came yesterday, when i replaced the cube by a real space ship model, a simple design made by my brother in Blender, and attached the same script my cube had, the lasers are instantiated very above from the space ship, producing the effect seen in the next image, the lasers are spawned at the red line i drew just for showing purposes, when i need them to be instantiated at the green line:
Here you can see the space ship model vs the cube, both firing lasers:
We designed the space ship model in blender, in the origin of coordinates, without any other objects or light sources, so my doubts are:
- Why are the lasers spawned that high if the model is not there? Is really the model bigger than i see in the editor? (The green box is a box collider i added for collisions managing)
- Should we configure or touch something in the Blender project to stablish the real size or axis of the model when we import it?
- Is there a better method of calculate where the lasers should be spawned that this one i am using? Imagine that i want to spawn them in the point of the wings, in front of them. Is there any marker or method i could use to easily spot the place where the lasers should be spawned at runtime? Instead of manual calculating it or by test-error.
I don't have the model here right now, if you need it please let me know and i will try to upload it to somewhere later.
Thank you so much for your help!