- Home /
Question by
siddharth3322 · Nov 25, 2014 at 02:10 PM ·
physics2dforcerotatearoundrelative rotation
Rotate object around certain point using phyics
I want to rotate my object on world certain point using physics not using transform or rotate. I want implementation that work on 2d game. Similar to following code snippet :
float copterSpeed = 4f;
float rotationSide = 1f;
float rotationSpeed = 180f;
void Update()
{
if (Input.GetMouseButton(0))
{
float rotation = rotationSpeed * rotationSide; //rotationSide > 0 for no rotation, 1 for counter-clockwise, -1 for clockwise.
transform.Rotate(Vector3.forward * rotation * Time.deltaTime);
transform.position += transform.right * copterSpeed * Time.deltaTime;
}
}
Similar implementation I want for physics based. I found following code also but it rotate object around local point
var velocity : int = 100;
var sphere : GameObject;
var slower : float;
var angle : float;
function FixedUpdate () {
var targetDir = sphere.transform.position - transform.position;
var forward = transform.forward;
var localTarget = transform.InverseTransformPoint(sphere.transform.position);
angle = Mathf.Atan2(localTarget.x, localTarget.z) * Mathf.Rad2Deg;
//angle = Vector3.Angle(targetDir, forward);
var eulerAngleVelocity : Vector3 = Vector3 (0, angle, 0);
var deltaRotation : Quaternion = Quaternion.Euler(eulerAngleVelocity * Time.deltaTime );
rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
}
Please give some suggestion for this problem.
Comment
Your answer
Follow this Question
Related Questions
rigidbody2D force or velocity? 2 Answers
how to calculate force direction on mouse up 1 Answer
AddForce on collision gives different results on different platforms 0 Answers
Game Object is moving towards the left when fire button is pressed. 2 Answers
Unity2d Set Different Physics Properties on Gameobjects (potentially at Runtime) 2 Answers