I share form what I learn ~~~~
This JavaScript is suitable for AI to Target Lock on our Avatar (suitable for Enemy) Here the script that I want to share with you all (Original form tornadotwins)
Only for Unity 3D
----------------------------------------------------------------------------------------------------------------
var LookAtTarget:Transform;
var damp = 6.0;
var bullitPrefab:Transform;
var savedTime=0;
function Update ()
{
if(LookAtTarget)
{
var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
var seconds : int = Time.time;
var oddeven = (seconds % 5);
if(oddeven)
{
Shoot(seconds);
}
}
}
function Shoot(seconds)
{
if(seconds!=savedTime)
{
var bullit = Instantiate(bullitPrefab ,transform.Find("spawnPoint").transform.position ,
Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
savedTime=seconds;
}
}
------------------------------------------------------------------------------------------------------------------
When you done copy this JavaScript. Save it and drag the JavaScript into the name of the Turret on the Hierarchy. Click the Turret that already have this Script and look at the Inspector and look for this Script. It will show Script , Look At Target , Damp , Bullit Prefab and Saved Time . Look for the (Look At Target and drag the Name of the Target from Hierarchy to let the Turret Look on it. For Bullit Prefab, just drag the name of the bullet that you already ready it for the turret to shoot it.
No comments:
Post a Comment