void Shoot(Collider2D target) { // Debug.Log("shoot"); GameObject bulletPrefab = towerData.CurrentLevel.bullet; // 1 Vector3 startPosition = gameObject.transform.position; Vector3 targetPosition = target.transform.position; startPosition.z = bulletPrefab.transform.position.z; targetPosition.z = bulletPrefab.transform.position.z; // 2 GameObject newBullet = (GameObject)Instantiate(bulletPrefab); newBullet.transform.position = startPosition; BulletBehaviour bulletComp = newBullet.GetComponent <BulletBehaviour>(); bulletComp.target = target.gameObject; bulletComp.startPosition = startPosition; bulletComp.targetPosition = targetPosition; // 3 // Animator animator = towerData.CurrentLevel.visualization.GetComponent<Animator>(); // animator.SetTrigger("fireShot"); // AudioSource audioSource = gameObject.GetComponent<AudioSource>(); // audioSource.PlayOneShot(audioSource.clip); }
private void CollectEnergy(BulletBehaviour bulletCB) { Debug.Log("EnergyCollected"); _energyHandler.RecieveSomeEnergy(bulletCB.GetEnergyAmount()); Destroy(bulletCB.gameObject); SoundManager.Instance.PlaySomeAudio("Pick"); }
public void ResetTrajectory(BulletBehaviour bulletToManage, float local, float parent) { enabled = true; bulletManaged = bulletToManage; degreeLocal = local; degreeParent = parent; }
// Update is called once per frame void Update() { bool isUpPressed = Input.GetKey(KeyCode.UpArrow); if (isUpPressed && !mWasUpPressed) { // Shoot GameObject newBullet = Instantiate(bullet); Transform child = transform.Find("Turret"); if (child != null) { BulletBehaviour bulletInfo = newBullet.GetComponent <BulletBehaviour>(); bulletInfo.Direction = new Vector3(1.0f, 0.0f, 0.0f); bulletInfo.ParentTag = gameObject.tag; newBullet.transform.position = child.position; } else { Debug.Log("Child not found!"); } } mWasUpPressed = isUpPressed; }
/// <summary> /// Perform and display the shot locally (i.e. only on this instance of the game). Does not /// communicate anything to other players (unless this is the server, in which case the server /// will determine the effects of the bullet). Does not do any validation. This should only be invoked /// when displaying the results of a shot (i.e. after receiving a ShootMessage or after this client performs a shot) /// or when server is determining the outcome of the shot. /// </summary> /// <param name="shooter">gameobject of the shooter</param> /// <param name="finalDirection">direction the shot should travel (accuracy deviation should already be factored into this)</param> /// <param name="damageZone">targeted damage zone</param> /// <param name="isSuicideShot">if this is a suicide shot (aimed at shooter)</param> public void DisplayShot(GameObject shooter, Vector2 finalDirection, BodyPartType damageZone, bool isSuicideShot) { //Add too the cooldown timer to being allowed to shoot again FireCountDown += 1.0 / FireRate; CurrentMagazine.ammoRemains--; //get the bullet prefab being shot GameObject bullet = PoolManager.Instance.PoolClientInstantiate(Resources.Load(Projectile.name) as GameObject, shooter.transform.position, Quaternion.identity); float angle = Mathf.Atan2(finalDirection.y, finalDirection.x) * Mathf.Rad2Deg; BulletBehaviour b = bullet.GetComponent <BulletBehaviour>(); if (isSuicideShot) { b.Suicide(shooter, this, damageZone); } else { b.Shoot(finalDirection, shooter, this, damageZone); } //add additional recoil after shooting for the next round AppendRecoil(angle); SoundManager.PlayAtPosition(FireingSound, shooter.transform.position); }
void Shoot(Collider2D target) { GameObject bulletPrefab = monsterData.CurrentLevel.bullet; //Get the start and target positions of the bullet. Set the z-Position to that of bulletPrefab. //Earlier, you set the bullet prefab's z position value to make sure the bullet appears behind the monster //firing it, but in front of the enemies. Vector3 startPosition = gameObject.transform.position; Vector3 targetPosition = target.transform.position; startPosition.z = bulletPrefab.transform.position.z; targetPosition.z = bulletPrefab.transform.position.z; //Instantiate a new bullet using the bulletPrefab for MonsterLevel. Assign the startPosition and targetPosition of the bullet. GameObject newBullet = (GameObject)Instantiate(bulletPrefab); newBullet.transform.position = startPosition; BulletBehaviour bulletComp = newBullet.GetComponent <BulletBehaviour>(); bulletComp.target = target.gameObject; bulletComp.startPosition = startPosition; bulletComp.targetPosition = targetPosition; //Make the game juicier: Run a shoot animation and play a laser sound whenever the monster shoots. Animator animator = monsterData.CurrentLevel.visualization.GetComponent <Animator>(); animator.SetTrigger("fireShot"); AudioSource audioSource = gameObject.GetComponent <AudioSource>(); audioSource.PlayOneShot(audioSource.clip); }
void Shoot(Monster target) { GameObject targetGo = target.go; Vector3 startPosition = gameObject.transform.position; Vector3 targetPosition = targetGo.transform.position; //startPosition.z = bulletPrefab.transform.position.z; //targetPosition.z = bulletPrefab.transform.position.z; GameObject newBullet = (GameObject)Instantiate(bulletPrefab); newBullet.transform.parent = transform; newBullet.transform.localScale = orginScale; newBullet.transform.position = startPosition; BulletBehaviour bulletComp = newBullet.GetComponent <BulletBehaviour>(); bulletComp.target = target; bulletComp.startPosition = startPosition; bulletComp.targetPosition = targetPosition; bulletComp.towerShoot = this; /*音效 * Animator animator = monsterData.CurrentLevel.visualization.GetComponent<Animator>(); * animator.SetTrigger("fireShot"); * AudioSource audioSource = gameObject.GetComponent<AudioSource>(); * audioSource.PlayOneShot(audioSource.clip); */ }
private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir, Vector3 hitPos) { forceDir.z = 0; Vector3 bulletHitTarget = hitPos + (forceDir * 0.2f); Vector3Int cellPos = metaTileMap.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget)); MetaDataNode data = metaDataLayer.Get(cellPos); if (Layer.LayerType == LayerType.Windows) { LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Windows); if (getTile != null) { //TODO damage amt based off type of bullet AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet); return; } } if (Layer.LayerType == LayerType.Grills) { //Make sure a window is not protecting it first: if (!metaTileMap.HasTile(cellPos, LayerType.Windows, true)) { if (metaTileMap.HasTile(cellPos, LayerType.Grills, true)) { //TODO damage amt based off type of bullet AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet); } } } }
public void move(BulletBehaviour bulletBehaviour) { switch (type) { case types.Regular: bulletBehaviour.rb.velocity = bulletBehaviour.direction * bulletSpeed; break; case types.Boomerang: bulletBehaviour.rb.velocity = bulletBehaviour.direction * bulletSpeed * ((bulletBehaviour.timeElapsed / -1) + 1); break; case types.Homing: Vector3 temp = (bulletBehaviour.cursor.position - bulletBehaviour.transform.position).normalized * Time.deltaTime * 5f; bulletBehaviour.direction += new Vector2(temp.x, temp.y); bulletBehaviour.rb.velocity = bulletBehaviour.direction * bulletSpeed; break; case types.Swerving: bulletBehaviour.rb.velocity = bulletBehaviour.direction * bulletSpeed; if ((bulletBehaviour.cursor.position - bulletBehaviour.transform.position).magnitude < (bulletBehaviour.cursor.position - (new Vector3(bulletBehaviour.rb.velocity.x, bulletBehaviour.rb.velocity.y, 0f) * Time.deltaTime) - bulletBehaviour.transform.position).magnitude && bulletBehaviour.swerveAvailable) { bulletBehaviour.swerveAvailable = false; temp = bulletBehaviour.cursor.position - bulletBehaviour.transform.position; temp = temp.normalized; bulletBehaviour.direction = new Vector2(temp.x, temp.y); } break; } }
// Update is called once per frame void Update() { if (time > 1 / barrel.fireRate) { if (Input.GetMouseButton(0)) { if (Input.GetMouseButtonDown(0) || barrel.automatic) { int bulletCounter = 0; while (bulletCounter < barrel.bulletAmount) { bulletBehaviour = Instantiate(bullet, transform.position + transform.up, transform.rotation).GetComponent <BulletBehaviour>(); bulletBehaviour.direction += new Vector2(transform.up.x, transform.up.y); bulletBehaviour.direction += new Vector2(Random.Range(-1 / barrel.accuracy, 1 / barrel.accuracy) * transform.right.x, Random.Range(-1 / barrel.accuracy, 1 / barrel.accuracy) * transform.right.y); bulletBehaviour.type = bulletMovement; bulletBehaviour.cursor = cursor; Destroy(bulletBehaviour.gameObject, bulletMovement.lifeTime); time = 0f; bulletCounter++; } } } } time += Time.deltaTime; }
public override void Fire() { RaycastHit hitInfo; int layerMask = ~(1 << 5); BulletBehaviour b = bulletPool.Create(Player, 0, MuzzleTrans.position) as BulletBehaviour; if (Physics.Raycast(Player.transform.position, Player.transform.forward, out hitInfo, 1000, layerMask)) { //Debug.Log("hitting: " + hitInfo.collider.gameObject.ToString()); b.TargetPos = hitInfo.point; } else { b.TargetPos = MuzzleTrans.position + this.transform.parent.forward; } if (this.effect != null) { b.Effect = this.effect; if (this.effect.hasColor) { this.effect.SetTargetColor(b.gameObject); } } b.Fire(); base.Fire(); }
//This is only for the shooters client and the server. Rest is done via msg private void Shoot(GameObject shooter, Vector2 direction, string bulletName, BodyPartType damageZone, bool isSuicideShot) { CurrentMagazine.ammoRemains--; //get the bullet prefab being shot GameObject bullet = PoolManager.Instance.PoolClientInstantiate(Resources.Load(bulletName) as GameObject, shooter.transform.position, Quaternion.identity); float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; //if we have recoil variance add it, and get the new attack angle if (CurrentRecoilVariance > 0) { direction = GetRecoilOffset(angle); } BulletBehaviour b = bullet.GetComponent <BulletBehaviour>(); b.isSuicide = isSuicideShot; b.Shoot(direction, angle, shooter, damageZone); //add additional recoil after shooting for the next round AppendRecoil(angle); SoundManager.PlayAtPosition(FireingSound, shooter.transform.position); }
public static void CheckBulletAABB(BulletBehaviour bullet, CubeBehaviour cube) { Contact contactB = new Contact(cube); if ((bullet.min.x <= cube.max.x && bullet.max.x >= cube.min.x) && (bullet.min.y <= cube.max.y && bullet.max.y >= cube.min.y) && (bullet.min.z <= cube.max.z && bullet.max.z >= cube.min.z)) { float[] distances = { (bullet.max.x - cube.min.x), (bullet.max.y - cube.min.y), (bullet.max.z - cube.min.z), (cube.max.x - bullet.min.x), (cube.max.y - bullet.min.y), (cube.max.z - bullet.min.z), }; float penetration = float.MaxValue; Vector3 face = Vector3.zero; for (int i = 0; i < 6; i++) { if (distances[i] < penetration) { penetration = distances[i]; face = faces[i]; } } bullet.penetration = penetration; bullet.collisionNormal = -face; Reflect(bullet); } }
void Shoot() { //Debug.Log(Camera.main.ScreenToWorldPoint(Input.mousePosition).ToString()); //SpriteRenderer tempRenderer= Instantiate(bullet, sightDirection.Find("Cannon").position, sightDirection.rotation).GetComponent<SpriteRenderer>(); GameObject tempObj = ObjectPoolerScript.current.GetPooledObject(); tempObj.transform.position = sightDirection.Find("Cannon").position; tempObj.transform.rotation = sightDirection.rotation; BulletBehaviour bullet = tempObj.GetComponent <BulletBehaviour>(); bullet.type = BulletBehaviour.BulletType.Player; SpriteRenderer tempRenderer = tempObj.GetComponent <SpriteRenderer>(); tempRenderer.color = spriteRendered.color; tempRenderer.sprite = SpriteManagerScript.current.playerBulllet; //Destroy(tempRenderer,2); TopDownCamMovement camera = Camera.main.GetComponent <TopDownCamMovement>(); camera.speed = 25; camera.impulseDirection = sightDirection.up; tempObj.SetActive(true); }
void Shoot() { GameObject bullet = Instantiate(Bullet, transform.position + new Vector3(1.5f, 0, 0), transform.rotation); BulletBehaviour bc = bullet.GetComponent <BulletBehaviour>(); bc.Velocity = transform.up * BulletSpeed; bc.Damage = BulletDamage; }
public void ResetTrajectory(BulletBehaviour bulletToManage, float local, float parent) { target = null; enabled = true; bulletManaged = bulletToManage; degreeLocal = 0; degreeParent = parent + local; }
private void hurtPlayer() { if (this.active && !this.immune) { EventManager.instance.onPlayerHurt(); } this.bulletHit = null; }
// Use this for initialization void Start() { rb = GetComponent <Rigidbody2D>(); sprite = GetComponent <SpriteRenderer>(); bulletBehaviour = GetComponent <BulletBehaviour>(); sprite.color = type.color; }
BulletBehaviour AddObjectToPool() { BulletBehaviour newBullet = Instantiate(prefab); newBullet.gameObject.SetActive(false); objectList.Add(newBullet); return(newBullet); }
public static void CheckSphereAABB(BulletBehaviour bullet, CubeBehaviour cube) { // get box closest point to sphere center by clamping var x = Mathf.Max(cube.min.x, Mathf.Min(bullet.transform.position.x, cube.max.x)); var y = Mathf.Max(cube.min.y, Mathf.Min(bullet.transform.position.y, cube.max.y)); var z = Mathf.Max(cube.min.z, Mathf.Min(bullet.transform.position.z, cube.max.z)); var distance = Math.Sqrt((x - bullet.transform.position.x) * (x - bullet.transform.position.x) + (y - bullet.transform.position.y) * (y - bullet.transform.position.y) + (z - bullet.transform.position.z) * (z - bullet.transform.position.z)); if ((distance < bullet.radius) && (!bullet.isColliding)) { // determine the distances between the contact extents float[] distances = { (cube.max.x - bullet.transform.position.x), (bullet.transform.position.x - cube.min.x), (cube.max.y - bullet.transform.position.y), (bullet.transform.position.y - cube.min.y), (cube.max.z - bullet.transform.position.z), (bullet.transform.position.z - cube.min.z) }; float penetration = float.MaxValue; Vector3 face = Vector3.zero; // check each face to see if it is the one that connected for (int i = 0; i < 6; i++) { if (distances[i] < penetration) { // determine the penetration distance penetration = distances[i]; face = faces[i]; } } bullet.penetration = penetration; bullet.collisionNormal = face; if (cube.hitByBullet == false) { cube.direction = new Vector3(0.0f, -1.0f, 0.0f); cube.speed = bullet.force; cube.hitByBullet = true; } else if (cube.isColliding) { cube.direction = bullet.collisionNormal; cube.speed = bullet.force; } bullet.speed *= 0.6f; Reflect(bullet); } }
public virtual void Shoot() { fireSound.Play(); BulletBehaviour newBullet = Instantiate(bulletPrefab, transform.position + transform.forward, transform.rotation).GetComponent <BulletBehaviour>(); newBullet.speed = 10; newBullet.damage = damage; newBullet.timeToLive = 5; }
/// <summary> /// Asteroid collider. /// </summary> /// <param name="collision">Object wich asteroid collided.</param> void OnCollisionEnter(Collision collision) { BulletBehaviour bullet = collision.gameObject.GetComponent <BulletBehaviour> (); if (bullet != null) { CmdDestroy(false); } }
void OnCollisionEnter2D(Collision2D collision) { BulletBehaviour shot = collision.gameObject.GetComponent <BulletBehaviour>(); if (shot != null) { Damage(10); } }
public void VolleyInitialize(Vector3 target) { speed = 5f; gameObject.SetActive(true); transform.LookAt (target); bulletBehaviour += Movement; SpriteRenderer sprite = GetComponentInChildren<SpriteRenderer>(); sprite.transform.rotation = Quaternion.identity; }
private void onBulletHit(Transform t, BulletBehaviour bb) { if (t.Equals(this.transform) && bulletHit == null) { this.bulletHit = bb; EventManager.instance.onBulletHitsPlayer(this, this.bulletHit); EventManager.instance.hurtPlayer(); } }
private void DetermineAction(GameObject objectColliding, Vector2 forceDirection) { BulletBehaviour bulletBehaviour = objectColliding.GetComponent <BulletBehaviour>(); if (bulletBehaviour != null) { DoBulletDamage(bulletBehaviour, forceDirection); } }
void CmdFire(Vector3 position, Quaternion rotation, string id, string name) { GameObject obj = _spawnManager.GetFromPool(); BulletBehaviour bullet = obj.GetComponent <BulletBehaviour> (); bullet.Fire(id, name, position, rotation); NetworkServer.Spawn(obj, _spawnManager.assetId); }
private void DetermineAction(GameObject objectColliding, Vector2 forceDirection, Vector3 hitPos) { BulletBehaviour bulletBehaviour = objectColliding.transform.parent.GetComponent <BulletBehaviour>(); if (bulletBehaviour != null) { DoBulletDamage(bulletBehaviour, forceDirection, hitPos); } }
public void triggerHit(BulletBehaviour bullet) { float c = BalancingGame.General.MasterDamage, p1 = BalancingGame.General.ArmaPowerInfluenceDamage, p2 = BalancingGame.General.DistanceInfluenceDamage; float damage = c * bullet.Aj / Fsm.Entity.Parameters.Defesa * (p1 * bullet.Aa * bullet.Aj + p2 / bullet.Rj / bullet.Rj); //Debug.Log(string.Format("Damage {1} {0}",damage,Fsm.Entity.NameChar)); Fsm.ChangeState(new CharacterHitState <CharacterBehaviour>(damage)); }
/// <summary> /// 本地注册 /// </summary> /// <param name="bulletBehaviour"></param> public void RegisteBullets(BulletBehaviour bulletBehaviour) { EntityModel bulletModel = new EntityModel(); bulletModel.GO = bulletBehaviour.gameObject; bulletModel.Behaviour = bulletBehaviour; m_localBulletList.Add(bulletModel); }
public void Initiate(BulletBehaviour bulletBehaviour, Vector3 spawnpoint, BulletKinematics bulletKinematics) { this.bounces = 0; this.previousPos = spawnpoint; this.bulletBehaviour = bulletBehaviour; this.spawnpoint = spawnpoint; this.bulletKinematics = bulletKinematics; }
float CalculateDamage(BulletBehaviour bullet){ if (bullet.projectileType == WeakAgainst) return bullet.bulletDamage * 2; if (bullet.projectileType == strongAgainst) return bullet.bulletDamage * 0.5f; if (bullet.projectileType == this.projectileType) // No te hago daño si me tiras mismo elemento... obviamente. return 0; return bullet.bulletDamage; }
// Update is called once per frame void Update() { if (Input.GetAxisRaw("Submit") > 0) { if(curBulletScript.curState == BulletBehaviour.State.FIRED) { curBullet = (GameObject)Instantiate(bulletPrefab, bulletStartPos, Quaternion.identity); curBulletScript = curBullet.GetComponent<BulletBehaviour>(); curBulletScript.curState = BulletBehaviour.State.AIM; } } }
void OnLevelWasLoaded(int levelID) { curBullet = (GameObject)Instantiate(bulletPrefab, bulletStartPos, Quaternion.identity); curBulletScript = curBullet.GetComponent<BulletBehaviour>(); curBulletScript.curState = BulletBehaviour.State.AIM; }