x


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!

more ▼

asked Aug 22 '11 at 05:33 PM

oldsoul gravatar image

oldsoul
16 1 1 1

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Aug 22 '11 at 06:53 PM

Joshua gravatar image

Joshua
6.4k 19 25 70

(comments are locked)
10|3000 characters needed characters left

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...

more ▼

answered Aug 22 '11 at 07:01 PM

oldsoul gravatar image

oldsoul
16 1 1 1

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.

Aug 22 '11 at 07:09 PM Joshua

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.

Aug 22 '11 at 07:27 PM oldsoul

Take a close look at where the pivot is at.

Aug 22 '11 at 07:31 PM Joshua

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!

Aug 22 '11 at 07:57 PM oldsoul

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.

Aug 22 '11 at 08:03 PM Joshua
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1783
x1090
x459
x40

asked: Aug 22 '11 at 05:33 PM

Seen: 658 times

Last Updated: Aug 23 '11 at 05:19 PM