Hey! I am trying to have an object move around a point, with the same distance from the point always. I want to allow the user to control the point, but my code doesn’t seem to do the job.
I am using InControl ( InControl: Introduction - Gallant Games )
var CAMERA_POSITION = Camera.main.gameObject.transform.position;
var SPEED_RATIO = 400;
float rightRotation = inputDevice.RightStickY * SPEED_RATIO;
float leftRotation = inputDevice.LeftStickY * SPEED_RATIO;
rightEmitter.transform.RotateAround (CAMERA_POSITION, Vector3.forward, rightRotation * Time.deltaTime);
It does move the object, but it isn’t moving in the obvious way you would expect a controller to move it.
Thanks a bundle!
I would suggest calculating the point with something like this and the using Math.Lerp() to make it smoother:
static Point RotatePoint(Point pointToRotate, Point centerPoint, double angleInDegrees)
{
double angleInRadians = angleInDegrees * (Math.PI / 180);
double cosTheta = Math.Cos(angleInRadians);
double sinTheta = Math.Sin(angleInRadians);
return new Point
{
X =
(int)
(cosTheta * (pointToRotate.X - centerPoint.X) -
sinTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.X),
Y =
(int)
(sinTheta * (pointToRotate.X - centerPoint.X) +
cosTheta * (pointToRotate.Y - centerPoint.Y) + centerPoint.Y)
};
}
static Point RotatePoint(Point pointToRotate, double angleInDegrees)
{
return RotatePoint(pointToRotate, new Point(0, 0), angleInDegrees);
}
static double DegreesToRadians(double angleInDegrees)
{
return angleInDegrees * (Math.PI / 180);
}
http://stackoverflow.com/questions/13695317/rotate-a-point-around-another-point
Can you explain a lil more how to go about integrating that?
How would I connect that to the controller input?