public void Aim() { if (attackTarget == null) { SetAim(false); return; } if (turretPivot == null) { SetAim(true); return; } Vector3 tgtPoint = attackTarget.GetTargetPoint(); float elevation = shootObject.GetElevationAngle(shootPoint[0].position, tgtPoint); if (!aimInXAxis || barrelPivot != null) { tgtPoint.y = turretPivot.position.y; } Quaternion wantedRot = Quaternion.LookRotation(tgtPoint - turretPivot.position); if (elevation != 0 && aimInXAxis && barrelPivot == null) { wantedRot *= Quaternion.Euler(elevation, 0, 0); } if (snapAiming) { turretPivot.rotation = wantedRot; } else { turretPivot.rotation = Quaternion.Lerp(turretPivot.rotation, wantedRot, aimSpeed * Time.deltaTime); SetAim(Quaternion.Angle(turretPivot.rotation, wantedRot) < 5); } if (!aimInXAxis || barrelPivot == null) { return; } Quaternion wantedRotX = Quaternion.LookRotation(attackTarget.GetTargetPoint() - barrelPivot.position); if (elevation != 0) { wantedRotX *= Quaternion.Euler(elevation, 0, 0); } if (snapAiming) { barrelPivot.rotation = wantedRotX; } else { barrelPivot.rotation = Quaternion.Lerp(barrelPivot.rotation, wantedRotX, aimSpeed * Time.deltaTime * 2); } }
private void UpdateTargetPos() { if (tgtUnit != null) { targetPos = tgtUnit.GetTargetPoint(); } else { tgtRadius = 0.1f; } }
public void InitShoot(Unit tUnit) { tgtUnit = tUnit; tgtRadius = tgtUnit.GetRadius(); targetPos = tgtUnit.GetTargetPoint(); shot = true; hit = false; shootTime = Time.time; if (type == _Type.Projectile) { //estimate the time taken to reach the target (roughly) and calculate the effective elevation based on falloffRange float dist = Vector3.Distance(GetPos(), targetPos); eta = dist / speed; effElevation = elevation * Mathf.Clamp((dist - (falloffRange * .5f)) / falloffRange, 0, 1); } else if (type == _Type.Beam) { if (shootPoint != null) { thisT.parent = shootPoint; } } else if (type == _Type.Effect) { thisT.LookAt(targetPos); } /* * else if(type==_Type.Missile){ * float dist=Vector3.Distance(GetPos(), targetPos); * eta=dist/speed; * * if(shootPoint!=null) thisT.rotation=shootPoint.rotation; * * float rotX=maxDeviation;//Random.Range(0, maxDeviation); * float rotY=Random.value>.5f ? -maxDeviation : maxDeviation; //Random.Range(-maxDeviation, maxDeviation); * missileOffset=thisT.rotation*Quaternion.Euler(-rotX, rotY, 0)*Vector3.forward*dist*0.65f; * } */ effectShoot.Spawn(GetPos(), GetRot()); AudioManager.PlaySound(shootSound); }