Hi, I need to optimize my teleportation gun in a few ways. Is there a way I can make it so that the instantiated object is affected differently to the original object? The gun is also pretty buggy, including where the original bullet spawns.
Gun Code:
#pragma strict
var bullet : Rigidbody;
var bulletPoint : Transform;
var bulletInstance : Rigidbody;
function Update ()
{
var power : int = 500;
var hit : RaycastHit;
if (Input.GetButtonDown("Fire1"))
{
var fwd: Vector3 = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast (transform.position, fwd))//Check if raycast hit
print ("Raycast Hit!");
else
print ("Raycast Didn't Hit!");
var bulletInstance: Rigidbody = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody; //Object to clone, origin of bullet, rotation
bulletInstance.AddForce(fwd * power); //Moving projectile
Quaternion.LookRotation(hit.normal);
}
}
Teleport Script:
var target : Transform;
function OnTriggerEnter( col : Collider )
{
player = GameObject.Find("Player");
if(col.gameObject.tag == "teleport")
{
player.transform.position = target.position;
}
}
Preview: http://i.imgur.com/QR7ESdZ.png
Any optimization help would be great.
↧