- Home /
When I set an explosion prefab on my object the explosion is way off centered?
I am very very new to Unity3D and i'm sure most of you are laughing at how silly of a question this is. Basically I have been following the TornadoTwins tutorials on YouTube and we made a turret game. The turrets (once we hit them with out projectile) would blow up. We made a script (ill put a picture of it below) so when the projectile destroys the turret it also makes an explosion. I got everything to go off, but when the explosion goes off it is way off to the side and not right on top of the debris of the turret? I dont understand, so if anyone can help that would be great :D
haha, Hmm This is a simple question but there are LOTS of variables involved! Like maybe the explosion is set to go off in a different position? Ask yourself questions like: 1. Is my explosion prefab handel (that 3 direction arrow pointer thats in your scene view) off to one side of the explosion? if so that maybe your answer! 2. $$anonymous$$aybe your turrent is supposed to be in a specific place relative to the world? (Unlikely)
Hmm cant think of much more at the moment keep posting pictures, like off the explosion ect you can do this by clicking the pause button right beside the play game button right when the explosion is about to happen and then click the next frame button to play the game one frame at a time :D
haha I did that exact same tutorial when i was first learning!
Posing a pic that shows where the explosion occurs compared with the turret would allow me to help more.
The script IS attached to the turret, correct?
It could just be that the pivot point of the turret is just waay off. I see at the top you're moving around the center. See the button that says "center"? Click it, and then see if now when you try to rotate the turret it rotates around an odd axis.
Otherwise, I can tell you how to work around the problem, but it's not really solving it
Answer by pickle chips · Jul 12, 2013 at 01:49 AM
Since it is a problem the the model, instead of editing the pivot point in another program, what you can do is set an offset on the x and z axis to position it on the turret. To do this, add this to your code: (By the way, for the future it's better to actually post your code, instead of a picture.)
//Add these variables here
public var xOffset : float;
public var zOffset : float;
//Then when you instantiate it:
var exp = Instantiate(explosion, Vector3(transform.position.x + xOffset, transform.position.y, transform.position.z + xOffset),Quaternion.identity );
This will instantiate it on the pivot point of the turret(where it is now), and then will move on the x and z axis according to the offset you assign it, which you can fiddle with in the inspector to get the right values.
If you still have problems leave a comment :p
//Add these variables here
public var x -9.594989 : float;
public var z -48.78781 : float;
//Then when you instantiate it:
var exp = Instantiate(explosion, Vector3(transform.position.x + xOffset, transform.position.y, transform.position.z + xOffset),Quaternion.identity );
Now I get errors from this?
@jscott You might want to learn how to do Unity Scripting at Walker Boys Studios.
var xOffset : float = -9.59f;
var zOffset : float = -48.78f;
Pickle chips gave a good answer. If you are happy with it, you should accept the answer (although I'd still prefer to edit my 3D models manually, having the script suggested is a good idea too).
Your answer
![](https://koobas.hobune.stream/wayback/20220613105938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help! My script wont work! 1 Answer
Help to code line of bullet like gunbound ! 1 Answer
I am not making Debug! 2D Toolkit and Unity 4 1 Answer
GUI Button to open an external document? HELP!!!! 3 Answers
Player model doesn't stay on ground 1 Answer