UNITY – JS Script – Input.GetAxis – AddTorque

AddTorque OnClick (aggiungere un momento torcente)

1. Create a Box with ‘Collider’ and ‘Rigid Body’

2. Inspector> Rigidbody> uncheck ‘Use Gravity’

3. Attach to the Box the script to AddTorque

#pragma strict

public var amount : float = 50f;


function FixedUpdate ()
{
    var h : float = Input.GetAxis("Horizontal") * amount * Time.deltaTime;
    var v : float = Input.GetAxis("Vertical") * amount * Time.deltaTime;
    
    rigidbody.AddTorque(transform.up * h);
    rigidbody.AddTorque(transform.right * v);
}

The Input.GetAxis Torque is additive!
You can try click arrow keys more times to see the effect!