public List <ShootAction> createActionShoot(GameObject target, int shotCount, float delayBetweenShots) { var ret = new List <ShootAction>(); for (int i = 0; i < shotCount; i++) { Vector3 shootPos = target.transform.position; float role = (float)random.NextDouble(); if (role <= mac.settings.shootSkill) { // success, no penalty } else { // TODO: needs improvement float yErr = (float)random.NextDouble() * (role * 10) - (role * 10 / 2); shootPos = target.transform.position + new Vector3(0, yErr, 0); } var dir = (mac.selfTransform.position - shootPos).normalized; var sc = new ShootAction(-dir); var delay = delayBetweenShots * i; var delayInTicks = (int)(delay / Time.fixedDeltaTime); sc.setDelay(delayInTicks); ret.Add(sc); } return(ret); }
void FixedUpdate() { if (createShootAction) { var action = new ShootAction(this, mousePos); loopTracker.RegisterAction(action); action.PlayAction(); createShootAction = false; if (loopTracker.IsPlayerControlled) { AudioManager.PlayClip(shootAudio, audioVolume, 0.3f); } else { AudioManager.PlayClip(shootAudio, 0.15f, 0.3f); } } if (currFixedFrame % mousePosTrackingInterval == 0) { loopTracker.RegisterMousePos(mousePos); //Debug.Log("Registering mouse pos at fixed frame: " + currFixedFrame); } currFixedFrame++; }
public override void Activate(Unit _, Action action, ActionController controller) { this.action = action as ShootAction; this.controller = controller as ShootActionController; instance = Instantiate(display, this.controller.rotationPoint.position, Quaternion.identity); instance.SetDisplayTarget(Vector2.right, this.controller.SpawnPointDistance, this.action.range + this.controller.SpawnPointDistance, this.action.bulletSpread); instance.SetPreviewMode(ActionPreviewDisplay.PreviewMode.Focus); }
public override void Activate(Unit _, Action action, ActionController controller) { this.action = action as ShootAction; this.controller = controller as ShootActionController; instance = Instantiate(display); instance.Init(); instance.SetPreviewMode(ActionPreviewDisplay.PreviewMode.Focus); }
public override void Execute(Action action, ActionTarget actionTarget) { currentAction = (ShootAction)action; currentTarget = actionTarget.targetLocation; rotateTo = rotationPoint.GetLookAtAngle(currentTarget); rotateTo = rotateTo < 0 ? 360 - Mathf.Abs(rotateTo) : rotateTo; active = true; nextShootTime = 0; bulletsLeft = currentAction.numberOfShoots; }
void Update() { if (action != null) { if (action is ShootAction) { ShootAction a = (ShootAction)action; shoot(action.player, a.x, a.y); } action = null; } GameObject[] gos = GameObject.FindGameObjectsWithTag("target"); if (gos.Length == 0) { Debug.Log("Game over"); restartLevel(); } }
//Method used for adding actions to the gun shoot event public void AddShootEvent(ShootAction action) { this.actions = action; }
private void OnDisable() { EventShootAITankAction -= Shoot; EventDeadAction -= ReSpawnTank; }
void OnEnable() { EventShootAITankAction += Shoot; EventDeadAction += ReSpawnTank; }
private void Start() { player = GameObject.FindGameObjectWithTag(Tags.Player).GetComponent <UserSoldier>(); gameManager = GameObject.FindGameObjectWithTag(Tags.GameController).GetComponent <GameManager>(); npc = GetComponent <NPCSoldier>(); npc.Damaged += Damaged; nextRadius = gameManager.nextRadius; SetCoverPos(transform.position); var notInSafeZoneCond = new ConditionNode(IsInSafeZone, false); var haveEnemyCond = new ConditionNode(HaveEnemyInSight, true); var beingShootCond = new ConditionNode(BeingShoot, true); var haveWeaponCond = new ConditionNode(HaveWeapon, true); var seekWeaponCond = new ConditionNode(SeekWeapon, true); var equipAction = new SetEquipmentAction(npc, true); var notEquipAction = new SetEquipmentAction(npc, false); var crouchAction = new SetCrouchAction(npc, true); var notCrouchAction = new SetCrouchAction(npc, false); var toSafeZoneAction = new MoveAction(npc, blackBoard, safeZoneKey); var goCoverAction = new MoveAction(npc, blackBoard, coverPosKey); var FallBackAction = new MoveAction(npc, blackBoard, fallBackPosKey); var goWeaponAction = new MoveAction(npc, blackBoard, weaponPosKey); var pickUpWeaponAction = new PickUpWeaponAction(npc, blackBoard, weaponKey); var shootAction = new ShootAction(npc, blackBoard, enemyPosKey); var turnToShooterAction = new TurnAction(npc, blackBoard, shooterPosKey); var idleAction = new IdleAction(npc); var combat = new SequenceNode(); combat.AddCondition(haveWeaponCond); combat.AddNode(equipAction); combat.AddNode(shootAction); var fallBack = new SequenceNode(); fallBack.AddNode(FallBackAction); haveEnemy = new SelectionNode(); haveEnemy.AddCondition(haveEnemyCond); haveEnemy.AddNode(combat); haveEnemy.AddNode(fallBack); var counter = new SequenceNode(); counter.AddCondition(haveWeaponCond); counter.AddNode(turnToShooterAction); beingShoot = new SelectionNode(); beingShoot.AddCondition(beingShootCond); beingShoot.AddNode(counter); beingShoot.AddNode(fallBack); toSafeZone = new SequenceNode(); toSafeZone.AddCondition(notInSafeZoneCond); toSafeZone.AddNode(notCrouchAction); toSafeZone.AddNode(notEquipAction); toSafeZone.AddNode(toSafeZoneAction); stayInCover = new SequenceNode(); stayInCover.AddCondition(haveWeaponCond); stayInCover.AddNode(goCoverAction); stayInCover.AddNode(crouchAction); stayInCover.AddNode(idleAction); seekWeapon = new SequenceNode(); seekWeapon.AddCondition(seekWeaponCond); seekWeapon.AddNode(goWeaponAction); seekWeapon.AddNode(pickUpWeaponAction); idle = new SelectionNode(); idle.AddNode(stayInCover); idle.AddNode(seekWeapon); root.AddNode(haveEnemy); root.AddNode(beingShoot); root.AddNode(toSafeZone); root.AddNode(idle); }
private void OnEnable() { EventShootAction += MakeShoot; EventDeadAction += ReSpawnTank; }
void Update() { if (!isFreeze) { return; } if (!m_TimelineManager.m_MoveTimeline.Locked) { if (Input.GetButtonDown("Horizontal")) { // Start recording horizontal movement m_StartActionTime = Time.time; float direction = GetMoveDirection(); float currentTime = Time.time; float duration = currentTime - m_StartActionTime; Action action = new MoveAction(m_StartActionTime - m_PlayTime, duration, direction, 1); m_TimelineManager.RecordAction(action); Move(direction); } if (Input.GetButton("Horizontal")) { float direction = GetMoveDirection(); float currentTime = Time.time; float duration = currentTime - m_StartActionTime; m_TimelineManager.m_MoveTimeline.UpdateDurationLastAction(duration); m_TimelineManager.m_MoveTimeline.UpdateDirectionLastAction(direction); Move(direction); } if (Input.GetButtonUp("Horizontal")) { float direction = GetMoveDirection(); float currentTime = Time.time; float duration = currentTime - m_StartActionTime; m_TimelineManager.m_MoveTimeline.UpdateDurationLastAction(duration); Debug.Log("Add new action at " + m_StartActionTime + ". Move timeline: " + m_TimelineManager.m_MoveTimeline.Length()); } } // Jump if (Input.GetButtonDown("Jump") && !m_TimelineManager.m_JumpTimeline.Locked) { float time = Time.time - m_PlayTime; Action action = new JumpAction(time); if (Jump()) { m_TimelineManager.RecordAction(action); } Debug.Log("Jump timeline: " + m_TimelineManager.m_JumpTimeline.Length()); } // Shoot if (Input.GetButtonDown("Fire1") && m_BulletRemaining > 0 && !m_TimelineManager.m_ShootTimeline.Locked) { float time = Time.time - m_PlayTime; Action action = new ShootAction(time); Fire(); m_TimelineManager.RecordAction(action); Debug.Log("Shoot timeline: " + m_TimelineManager.m_ShootTimeline.Length()); } }