- Home /
Rotation of GameObject w/ no movement
2D top down game. All movement is in the X and Z axis and rotation is in Y axis only.
I am using a GameObject with a Sphere Collider and a RigidBody. The RigidBody is set to be Kinematic.
I am manually moving the GameObject around w/
GameObject.tranform.Translate(horizontalSpeed, 0, verticalSpeed);
Positioning is extremely important in what I am doing so if I do not keep track of every single x and z movement, everything gets completely fouled up.
All I want to do is rotate (pivot) the GameObject w/out moving it in any direction. The anchor point of the object is dead center of the object.
Every example I have found uses either GameObject.transform.Rotate(), GameObject.transform.RotateAround() or GameObject.transform.rotation = Quaternion-something...
No matter what I do, the GameObject will always move a little in the X or Z direction. I cannot have this. All I want is the object itself to rotate around its center point at the angle I specify.
Thank you!
PAR
Answer by Dracorat · Apr 17, 2013 at 11:11 PM
If its moving some with those functions, the pivot point is wrong.
Double check it in your modeling program, also check that when you created the prefab, that you zeroed out the coordinates for all the relevant parts.
That could also be the most likely answer. Check the pivot point
Answer by ExpiredIndexCard · Apr 17, 2013 at 11:12 PM
Use a rigidbody and restrict it from moving. Ps you can still move the object through script. Ie. if you press 'up' the object will still move
Answer by par-002 · Apr 18, 2013 at 12:10 AM
Thanks for the replies but it turns out I was doing things incorrectly.
I am porting a game I did on iOS. There, movement was done via the Accelerometer. When I rotated the object, I did it incrementally based on the acceleration and velocity of the object.
Here, I am doing key inputs WASD and arrows. I shouldn't be doing the rotation based on increments of the velocity because the keys are "pretty close" to all or nothing. With that in mind, I changed my algorithm to do the angle between the magnitude of the horizontal speed vs the magnitude of the vertical speed. Tweaking for deceleration, I got it to do exactly what I wanted.
While you guys didn't have the right answer, it's not your fault due to me asking the wrong question :)
Sorry about that and thanks!
PAR