Hey guys,

Let’s say I have “cube A” and “cube B”. How can I add relative torque to cube B until it’s facing cube A and then stop?

Bump!

Basically I want to make a physics-based homing missile.

Got it. duckets from the IRC helped me with it. Basically, it’s a torque based lookat script.

``````using UnityEngine;
using System.Collections;

// @robotduck 2011
// set the object's rigidbody angular drag to a high value, like 10

public class TorqueLookAt : MonoBehaviour {

public Transform target;
public float force = 0.1f;

// Update is called once per frame
void Update () {

Vector3 targetDelta = target.position - transform.position;

//get the angle between transform.forward and target delta
float angleDiff = Vector3.Angle(transform.forward, targetDelta);

// get its cross product, which is the axis of rotation to
// get from one vector to the other
Vector3 cross = Vector3.Cross(transform.forward, targetDelta);

// apply torque along that axis according to the magnitude of the angle.

}
}
``````
2 Likes

The script reference advises to to use force related stuff in FixedUpdate instead of Update. By the way does it overshoot or oscillate?

If rigidbody angular drag is high enough it won’t oscillate

Then it becomes physically unrealistic. It is like placing the CG underground in racing games. The realistic solution lies in control engineering methods.

Then you will need to do some extra math to dampen the oscillation like counter-torque when approaching the correct angle. This was never a debate about realism

Yes, this was never a debate, I just asked dtoliaferro a question as he said “Basically I want to make a physics-based homing missile”. What I understand from “physics-based homing missile” is a realistic physics behaviour. I am still waiting for an answer from dtoliaferro.

Well if you’re gonna be an ass (read: the opposite of most folk on the unity forums…)

I applied the script before I replied - yes it overshoots its rotation / oscillates if the angular drag isn’t high enough. Fudging with the force (thrust in the case of a missile) values and finding a good torque-force can lead to some interesting behavior in missiles for a Game.

You can PM me if you want to discuss how (maybe even why) to simulate air density, surface effect forces, or known documented missile guidance systems’ infrared gimbals and how they’ve evolved over the last 50 years to the point where we can implement them in a Game and be happy with the results. </inner_asshole>

edit
pardon me - I’m assuming we’re talking about a game-ish project; if not then i apologize.

I am sorry if I somehow offended you. I wanted to do some game physics related discussion.