void CmdFire(Vector3 firePos, Vector3 eulerAngles) { GameObject rocket = Instantiate(projectile, firePos, Quaternion.identity); //make rocket ignore collision with the player who fired it rocket.gameObject.layer = 9; Physics2D.IgnoreCollision(rocket.GetComponent <CircleCollider2D>(), transform.GetChild(0).GetComponent <CircleCollider2D>(), true); NetworkServer.Spawn(rocket); // rocket.transform.position = firePos; // rocket.transform.rotation = eulerAngles; projectileController pC = rocket.GetComponent <projectileController>(); pC.velo = pC.speed * (new Vector2(Mathf.Cos(Mathf.Deg2Rad * (eulerAngles.z - 90)), Mathf.Sin(Mathf.Deg2Rad * (eulerAngles.z - 90)))).normalized; pC.playerWhoFiredThis = transform; pC.netIdOfWhoFiredThis = netId; //Debug.Log(transform.gameObject.name + " netId = " + netId + " fired a rocket"); pC.Fire(); //below is the old formula // pC.Fire(new Vector2(Mathf.Cos(Mathf.Deg2Rad * (transform.GetChild(0).rotation.eulerAngles.z - 90)), Mathf.Sin(Mathf.Deg2Rad * (transform.GetChild(0).rotation.eulerAngles.z - 90)))); hasFired = true; //Debug.Log("angle: " + (this.transform.rotation.eulerAngles.z - 90) + "\nexpanded vector:" + new Vector2(Mathf.Cos(Mathf.Deg2Rad * (this.transform.rotation.eulerAngles.z - 90)), Mathf.Sin(Mathf.Deg2Rad * (this.transform.rotation.eulerAngles.z - 90)))); //RaycastHit2D test = Physics2D.Raycast((Vector2)(transform.position), new Vector2(Mathf.Cos(Mathf.Deg2Rad * (this.transform.GetChild(0).rotation.eulerAngles.z - 90)), Mathf.Sin(Mathf.Deg2Rad * (this.transform.GetChild(0).rotation.eulerAngles.z - 90))), distance: Mathf.Infinity, layerMask: 13); //if (!isGrounded) // numRocketsLeft -= 1; //if (test.collider != null) //Debug.Log(test.collider.gameObject.name + " " + Vector2.Distance((Vector2)(test.transform.position), (Vector2)transform.position)); //projectile.transform.position = new Vector3(test.point.x, test.point.y, projectile.transform.position.z); //if (Vector2.Distance(test.point, (Vector2)transform.position) < explosionRadius && numRocketsLeft > 0) //if (isGrounded) // numRocketsLeft += 1; }
protected virtual void OnTriggerEnter(Collider other) { if (other.tag.Equals("Projectile")) { projectileController proj = other.gameObject.GetComponent <projectileController> (); if (proj.m_shooter != this.gameObject) { if (proj.m_shooter.tag.Equals("Player")) { m_healthController.TakeDamage(proj.m_damage); Vector3 shootForce = player.GetComponent <playerShoot> ().m_pushForce *(this.transform.position - proj.m_shooter.transform.position); this.rigidbody.AddForceAtPosition(shootForce, this.transform.position); if (!proj.isPiercing) { Destroy(other.gameObject); } } } } }
// Start is called before the first frame update void Awake() { myPC = GetComponentInParent <projectileController>(); }
public GameObject explosionEffect; //reference to the explosion particle // Use this for initialization void Awake() { myPC = GetComponentInParent <projectileController>(); //allows you to access the projectileController on this script }
void Awake() { PC = GetComponent <projectileController>(); }
public void shootProjectile() //create a new projectile object { projectileController p = Instantiate(projectile, transform.position, transform.rotation).GetComponent <projectileController>(); p.angle = owner.GetComponent <weaponSheath>().weapon_angle; //set the angle the bullet travels at }
// Start is called before the first frame update void Awake() { //Allows you to interact with the projectileController methods myPC = GetComponentInParent <projectileController>(); }