hey guys I am a begginer user of unity3d and i would like to learn how i can make fireballs which are shooted by my turrets (and are trigger) not to pass through spesific walls or grounds i have put… so here is my scripts
Movement Script:
//Moving Around
var speed = 3.0;
var rotateSpeed = 3.0;
var mouserotationSpeed : float = 5.0;
//Shooting
var bullitPrefab:Transform;
//Dying
static var dead = false;
//Getting Hit
var tumbleSpeed = 800;
var decreaseTime =.01;
var decayTime = 0.01;
static var gotHit = false;
private var backup = [tumbleSpeed, decreaseTime, decayTime];
//Jump
var jumpSpeed : float = 8.0;
var gravity : float = 5.0;
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0,20,0);
gameObject.Find("Main Camera").transform.position = Vector3(0,4,-10);
dead = false;
}
if(gotHit)
{
if(tumbleSpeed < 1)
{
//we're not hit anymore... reset & get back in the game!
tumbleSpeed = backup[0];
decreaseTime = backup[1];
decayTime = backup[2];
gotHit = false;
}
else
{
//we're hit! Spin our character around
transform.Rotate(0,tumbleSpeed * Time.deltaTime,0, Space.World);
tumbleSpeed = tumbleSpeed - decreaseTime;
decreaseTime += decayTime;
}
}
}
//function OnControllerColliderHit(hit:ControllerColliderHit)
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
HealthControl.LIVES -= 1;
}
if(hit.gameObject.tag == "enemyProjectile")
{
gotHit = true;
HealthControl.HITS += 1;
Destroy(hit.gameObject);
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
{
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
transform.Rotate(Vector3(0, Input.GetAxis("Mouse X"), 0) * Time.deltaTime * mouserotationSpeed);
if(Input.GetButton("Jump"))
{
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
//shoting
if(Input.GetButtonDown("Fire1"))
{
var bullit = Instantiate(bullitPrefab, transform.Find("Spawn").transform.position, Quaternion.identity);
bullit.tag = "wormProjectile";
bullit.rigidbody.AddForce(transform.forward * 3000);
}
if(transform.position.y < -200)
{
dead = true;
HealthControl.LIVES -= 1;
}
}
@script RequireComponent(CharacterController)
Turret Script:
var distanceTillShoot : float;
var LookAtTarget : Transform;
var damp : float = 6.0;
var bulletPrefab : GameObject;
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 % 2);
if(oddeven)
Shoot(seconds);
transform.LookAt(LookAtTarget);
}
}
function Shoot(seconds)
{
if(seconds!=savedTime)
{
var bullet = Instantiate
(bulletPrefab, transform.Find
("spawnPoint").transform.position,
Quaternion.identity);
bullet.gameObject.tag =
"enemyProjectile";
bullet.rigidbody.AddForce
(transform.forward * 2500);
savedTime=seconds;
}
}