Skip to content

Instantly share code, notes, and snippets.

View tracend's full-sized avatar
🎯
Focusing

✌ Makis Tracend tracend

🎯
Focusing
View GitHub Profile
@tracend
tracend / Unity3D: Planetery Gravity .js
Created March 28, 2011 23:10
Centerax is the center of the planet... by visioneleven (http://www.youtube.com/user/visioneleven)
object.rigidbody.velocity += (centerax.transform.position - object.transform.position).nor­malized * 10 * Time.deltaTime;
@tracend
tracend / CameraRotate.js
Created March 29, 2011 23:12
Unity3D: Rotate the camera every frame so it keeps looking at the target - Source: http://wiki.dreamsteep.com/Unity3d
var target : Transform;
// Rotate the camera every frame so it keeps looking at the target
function Update() {
transform.LookAt(target);
}
@tracend
tracend / MeasureDistance.js
Created March 29, 2011 23:13
Unity3D: Measure distance
function Update() {
if ( Vector3.Distance( enemy.position, transform.position ) < 10 )
print("I sense the enemy is near!");
}
@tracend
tracend / ExecuteInEditMode.js
Created March 29, 2011 23:16
Unity3D: A simple script that looks at the target transform - Source: http://wiki.dreamsteep.com/Unity3d
// Make the script also execute in edit mode.
@script ExecuteInEditMode()
// Just a simple script that looks at the target transform.
var target : Transform;
function Update () {
if (target)
transform.LookAt(target);
}
@tracend
tracend / QuitFunction.js
Created March 29, 2011 23:19
Unity3D: Quit button
function OnGUI () {
if (GUI.Button (Rect (25, 25, 100, 30), "Quit")) {
Application.Quit();
}
}
@tracend
tracend / Shoot.js
Created March 29, 2011 23:21
Unity3D: Simple shooting function - Source: http://wiki.dreamsteep.com/Unity3d
var prefabBullet: Transform;
var shootForce: float ;
function Update () {
if(Input.GetButtonDown("Shoot") )
{
var instancebullet =Instantiate( prefabBullet ,transform.position,Quaternion.identity);
instancebullet.rigidbody.AddForce(transform.forward * shootForce);
}
@tracend
tracend / deltaTimeExample.js
Created March 29, 2011 23:24
Unity3D: Frame rate independent calculations using Time.deltaTime - Source: http://unity3d.com/support/documentation/ScriptReference/Time-deltaTime.html
function Update () {
// Move the object 10 meters per second!
var translation : float = Time.deltaTime * 10;
transform.Translate (0, 0, translation);
}
@tracend
tracend / DynamicText.js
Created March 29, 2011 23:43
Unity3D: Updating a gui text field dynamically - Source: http://wiki.dreamsteep.com/Unity3d
function Update () {
var someNumber = groundtrigger.triggered;
var string= someNumber.ToString();
guiText.text = string; //typeof (groundtrigger.triggered);
}
@tracend
tracend / RaycastShooting.js
Created March 29, 2011 23:53
Unity3D: Use raycasts to create projectiles - Source: http://answers.unity3d.com/questions/4867/using-raycast-to-shoot
var par : ParticleEmitter;
var damage = 2;
function Update () {
var hit : RaycastHit;
// Use Screen.height because many functions (like this one) start in the bottom left of the screen, while MousePosition starts in the top left
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Input.MousePosition.x, Screen.height - Input.MousePosition.y,0));
if (Input.GetMouseButtonDown(0)) {
@tracend
tracend / MachineGun.js
Created March 29, 2011 23:57
Unity3D: A shooting routine - Source: http://wiki.dreamsteep.com/Unity3d
//My First Unity tool , it will shooot stuff , Keith Legg Jan 24
//to use drag this script to the main camera (or a vehicle's transform node ) , then drag a prefab to the bullet channel on the right
//be sure to adjust force/rate of fire so bullets dont hit each other when instantiated (example: higher force = slower the rate)
//space bar will fire gun on positive Z axis
//for a good default try 1000 force , 3 shots , and .1 second delay
var bullet: Transform;
var shootForce: float ;
var fullauto: boolean = true;