silver516 писал(а):А скрипт турели не продемонстрируете? (если не секрет конечно)
using UnityEngine;
using System.Collections;
public class CannonController : MonoBehaviour {
public Transform WeaponSlotObject;
CannonSlotController Slot;
public Transform PitchController;
public Transform YawController;
private float CurPitch = 0.0f;
private float CurYaw = 0.0f;
public float YawSpeed = 90.0f;
public float PitchSpeed = 90.0f;
public bool canPitch = false;
public bool canYaw = false;
private bool canFire = false;
public IGameLogicObject Target;
private IShootingController ShootControl;
public float ShotingDeltaAngle = 1.0f;
private TargetAimPredicator itsAimPredicator;
public LayerMask EnemyLayers;
private Transform Gun;
public float AreaRadiusKoef = 1.0f;
public AudioSource PitchRotateSound;
public AudioSource YawRotateSound;
//for debug
//public Vector3 AimPos;
// Use this for initialization
void Start () {
Slot = WeaponSlotObject.gameObject.GetComponent<CannonSlotController>();
/*if (PitchController)
canPitch = true;
if (YawController)
canYaw = true;*/
ShootControl = gameObject.GetComponentInChildren<IShootingController>();
if (!ShootControl)
Debug.Log("NO SHOOT CONTROLLER!");
Gun = ShootControl.Guns[0].Gun;
if (!Gun)
Debug.Log("No gun set!");
itsAimPredicator = new TargetAimPredicator();
}
// Update is called once per frame
void Update () {
if (!Target || Target.GetHP()<=0) // no target or target kill
{
ShootControl.SetCanFire(false, Vector3.zero, 5.0f, 0.0f);
SelectNewTarget();
return;
}
Vector3 Pos = Target.GetPosition();
if (itsAimPredicator.CanPredicate())
{
Pos = itsAimPredicator.AimPredicate();
}
canFire = Slot.isInSector(ref Slot.Sector, Pos);
//Debug.Log("can fine: "+canFire);
if (!canFire) // target not in sector
{
ShootControl.SetCanFire(false, Vector3.zero, 5.0f, 0.0f);
SelectNewTarget();
return;
}
// рысканье
if (canYaw)
{
Vector3 LocalYawPos = YawController.InverseTransformPoint(Pos);
float YawAngle = Mathf.Atan2(LocalYawPos.x, LocalYawPos.z) * Mathf.Rad2Deg;
if (YawRotateSound)
{
if (YawAngle>0.5f)
YawRotateSound.Play();
else
YawRotateSound.Stop();
}
//float CurYawAngle = YawAngle * Time.deltaTime;
float AbsCurYaw = Mathf.Abs(YawAngle);
float ResultAngle = 0.0f;
if (AbsCurYaw<YawSpeed*Time.deltaTime)
ResultAngle = YawAngle;
else
ResultAngle = Mathf.Sign(YawAngle) * YawSpeed*Time.deltaTime;
CurYaw += ResultAngle;
YawController.Rotate(0.0f, ResultAngle, 0.0f);
}
// тангаж
Vector3 LocalPitchPos = PitchController.InverseTransformPoint(Pos);
if(canPitch)
{
float PitchAngle = -Mathf.Atan2(LocalPitchPos.y, LocalPitchPos.z) * Mathf.Rad2Deg;
if(PitchRotateSound)
{
if (PitchAngle>0.5f)
PitchRotateSound.Play();
else
PitchRotateSound.Stop();
}
//float CurPitchAngle = PitchAngle * Time.deltaTime;
float AbsCurPitch = Mathf.Abs(PitchAngle);
float ResultAngle = 0.0f;
if (AbsCurPitch<PitchSpeed*Time.deltaTime)
ResultAngle = PitchAngle;
else
ResultAngle = Mathf.Sign(PitchAngle) * PitchSpeed*Time.deltaTime;
CurPitch += ResultAngle;
PitchController.Rotate(ResultAngle, 0.0f, 0.0f);
}
float AngleToTarget = Vector3.Angle(LocalPitchPos, Vector3.forward);
//Debug.Log("in sector: "+canFire+", angle: "+AngleToTarget+", distance: "+(Pos-transform.position).magnitude+", target: "+Target.GetPosition()+", aim: "+Pos);
if (AngleToTarget < ShotingDeltaAngle)
ShootControl.SetCanFire(true, Pos-transform.position, Target.GetSphereSize() * Target.GetSpeedPercent() * AreaRadiusKoef, itsAimPredicator.LastPredicatedTime());
else
ShootControl.SetCanFire(false, Pos-transform.position, Target.GetSphereSize() * Target.GetSpeedPercent() * AreaRadiusKoef, itsAimPredicator.LastPredicatedTime());
}
void SetNewTarget(IGameLogicObject target)
{
//Debug.Log(target.gameObject.name);
itsAimPredicator.UpdatePredicator(Gun, target, ShootControl.BulletVelocity);
}
void SelectNewTarget()
{
float MaxDistance = ShootControl.ShotingRange;
Collider [] clds = Physics.OverlapSphere(transform.position, MaxDistance, EnemyLayers);
MaxDistance = MaxDistance * MaxDistance;
//Debug.Log(clds.GetLength(0));
foreach(Collider c in clds)
{
IGameLogicObject obj = c.gameObject.GetComponent<IGameLogicObject>();
if (obj)
{
float WorkDistance = (obj.GetPosition() - transform.position).sqrMagnitude;
if (MaxDistance>WorkDistance && obj.GetHP()>0)
{
MaxDistance = WorkDistance;
Target = obj;
}
}
}
if (Target)
{
SetNewTarget(Target);
}
}
}
Ну дык, космос. Для процесса горения, как мне помнится, нужен кислород, в кораблике для кратковременной вспышки он есть. А в снаряде откуда?Интересно, а почему именно эти разрывы выглядят диковато? Когда кораблик взорвался ничего, а снаряд взорвался диковато?
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2