Hello.
I am working on a game where player controlled object is moving along circular path, with fixed radius and fixed center position, the object’s front always looking towards positive Z. So it is basically an object which can only move along the inner edge of an imaginary cylinder of a fixed radius, who’s main axis is Z. Holding the left key reduces the euler angle relative to start angle, holding the right key increases it.
The main part of achieving this circular motion is in these two lines:
rotation.eulerAngles = Vector3(0, 0, currentRotation);
transform.position = rotation * radius;
// currentRotation is angle relative to starting position, and is increased or decreased by horizontal input each frame
// radius is fixed value Vector3(4.0,0,0), holds radius of imaginary cylinder
// the transform.position = rotation * radius; is a formula I found online and it is doing the job, but I guess may be responsible for the problem I have
The problem I have is the object’s speed of revolving left or right is uneven, it will move faster either left or right. Also the key which is working slower at the time will have slight lag before moving the object. Later I found out it will move faster if moving towards currentRotation value of zero. So if currentRotation is lets say 100 and I hold left key (which reduces that number) it will move faster than if using the right key. And if currentRotation is lets say -100 then the right key (which increases the value towards zero) will make it move faster.
You may have guessed by now that I’m not good with mathematics and geometry, but what I know for sure is that the problem is definitely not in some phantom input or somewhere else in code, I have spent weeks now analyzing and checking everything. It is quite clear that the object is moving faster when the currentRotation value is moving towards zero, so the problem must be in the method that I’m using, so maybe someone here may shed some light on this issue.
function Update () {
var steerPower:float = Input.GetAxis("Horizontal");
steerPower *= (130*Time.deltaTime);
currentRotation += steerPower;
rotation.eulerAngles = Vector3(0, 0, currentRotation);
transform.position = rotation * radius;
//result is the movement will be faster and lag-free when the value of currentRotation is moving towards zero, and will be slow to start and move slower if the same value is moving away from zero
}
Please help… Been stuck with this for a while, and is preventing me from making the game controls feel as responsive as they should.