- Home /
Turret floats away and pushes everything away from it
For some reason when I apply this script to my turret:
var LookAtTarget:Transform; var damp = 1.0; function Update ()
{ if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp); }
//transform.LookAt(LookAtTarget);
}
It pushes any other objects nearby away, floats around, and when I get near it with the target it is tracking it floats up higher until I get farther away. I have trolled around looking for this exact problem and have not found any solutions posted to this question, I am fairly new to unity so I am certain it is just some stupid setting I am not familiar with. I have messed with rigidbody and other gravity settings trying to get something to work, but the object doesn't pay any attention to my feeble attempts.
Any suggestions are much appreciated!
Answer by Joshua · Aug 22, 2011 at 06:53 PM
You've probably given the body of the turret a rigidbody. Remove this. You don't want the gun to react physically realistically, eq push itself away.
Answer by oldsoul · Aug 22, 2011 at 07:01 PM
No, it doesn't have any rigidbody dynamics assigned to it right now. I have tried adding physics to it through the inspector tab and scripting, but nothing gets it to "act right." It just goes ape-S*** if you try to assign anything to it really. Probably worth noting I made the sphere (body), cylinder (barrel), and cube (base) and didn't import them, I don't know if that made me skip a step or what have you...
Please don't answer your own question if you want to comment - there's a button to do that. It makes others less likely to answer.
An object doesn't move unless you make it move somehow. If you haven't assigned a rigidbody component to any of the parts that make up the turret then you're moving it through script somehow. The only other option is that transform.rotation is rotating it around it's pivot, like it should, and you've put it's pivot at the wrong place.
Well I've cut my script down to the most basic parts: var LookAtTarget:Transform; function Update () { transform.LookAt(LookAtTarget); } And it still moves around and floats when I get near it. But also, any other nearby objects get pushed way far away. I don't know how in the world it is doing it. When I disable the script, it doesn't do it. I'm really pretty dumbfounded how it could be doing this. I have to take off for now, so if I don't reply for a while sorry.
Thanks both of you for your help though!
sorry, didn't know that about answer vs comment button.
I'm guessing you mean pivot / center button? I just switched it back and forth a few times and it didn't have any affect on what it is doing. Interesting, when it is set to pivot, the handle is way the heck out in front of it. Does that need to be moved, should it be set to just pivot and not center? Or is that not important? I gotta run, thanks for the help again!
Never put that button on center, put it on pivot. The pivot is the point around which an object moves and rotates. If you set it to pivot and the handle is not where you want it's physical center to be then you've found the cause of the problem. Put everything childed to it in the correct place and it should behave as expected.
Your answer
Follow this Question
Related Questions
changing gravity for one object. 5 Answers
My rigidbody gets destroyed 2 Answers
Gravitational pull without losing speed 1 Answer
RigidBodys Suddenly Heavier 1 Answer