ConstantVelocity

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Text replace - "<javascript>" to "<syntaxhighlight lang="javascript">")
m (Text replace - "</javascript>" to "</syntaxhighlight>")
Line 43: Line 43:
 
         rigidbody.velocity =  transform.rotation * direction;
 
         rigidbody.velocity =  transform.rotation * direction;
 
     }
 
     }
</javascript>
+
</syntaxhighlight>

Revision as of 20:52, 10 January 2012


Author: Opless

Description

Useful for missiles, grenades, etc

CSharp - ConstantVelocity.cs

using UnityEngine;
using System.Collections;
 
public class ConstantVelocity : MonoBehaviour {
 
	public Vector3  direction      = Vector3.forward;
 
	// Use this for initialization
	void Start () 
	{
	}
 
	// Update is called once per frame
	void Update () 
	{
		rigidbody.velocity =  transform.rotation * direction;
	}
}

Javascript - ConstantVelocity.js

    var direction : Vector3 = Vector3.forward;
 
    function Update ()
    {
        rigidbody.velocity =  transform.rotation * direction;
    }
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox