- Home /
object placement on sphere, rotation deform
So i have a Tower Defense game that im making, and im attaching my towers to a sphere wich is the game level. But the tower is deformed when an enemy comes in range and it rotates towards it.
void Update ()
{
if (target) {
aim_pan.LookAt (target);
aim_pan.eulerAngles = new Vector3 (0, aim_pan.localEulerAngles.y, 0);
aim_tilt.LookAt (target);
pivot_pan.rotation = Quaternion.Lerp (pivot_pan.rotation, aim_pan.rotation, Time.deltaTime * turnSpeed);
pivot_tilt.rotation = Quaternion.Lerp (pivot_tilt.rotation, aim_tilt.rotation, Time.deltaTime * turnSpeed);
if (Time.time >= nextFireTime) {
FireProjectile ();
}
}
}
this is what rotates the tower, when i first place it its rotation is correct. aim_pan and aim_tilt are child objects. The base that rotates arount the y and the top that tilts up and down
GameObject newStructure = Instantiate (allStructures [structureIndex],
lastHitObject.transform.position, lastHitObject.transform.parent.rotation) as GameObject;
this is the instantiation of the tower, lastHitObject is a child plane to the sphere world. its rotated correctly aswell.
Not sure that I understand 100%, but here's a few things to try:
On the LookAt functions, specify the second parameter "up" to be the sphere's normal at that position.
Ins$$anonymous$$d of using transform.rotation, try using transform.localRotation.
I figured it out it was th aim_pan.eulerAngles, changed it to localEulerAngles.
Answer by AntonyBaasan · May 12, 2015 at 09:49 AM
Usually deformation happens, if you put too big number after decimal point in scale parameter of a parent Transform.
For example:
Bad scale x=3.44345454, y=5.454353453, z=4.3240003
Good scale x=3.44, y=5.45, z=4.32
Good luck.
depending on the towers structure it could be that the parent object has a bizarre scale like Vector3(1,3,1) or similar so that when the child objects get rotated they scale with the parent and thus end up deformed as well.
It was some local rotations, but thanks for the info. i didnt know this, will be $$anonymous$$dfull of scales :)
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
RotateAround reversing doesn't work with negative vector3 0 Answers
Third person follow camera on a sphere 1 Answer
Rotating Sphere With Mouse 2 Answers
Camera rotation behaving strangely 2 Answers