Quantcast
Viewing all articles
Browse latest Browse all 1488

2D sidescroller ranged character shooting problem.

So i have been trying to create an archer in my 2d sidescroller, who has an invisible box infront of him, and when the player enter, i want the archer to fire arrows straightfoward (Kinda like the cannons in mario 3). My idea was to make the arrow spawn at the archers position and fly forwards. But i am having some problems. Here is my code so far. #pragma strict var Attack : boolean; var Archer : boolean; var Ammo : GameObject; var AmmoSpawnPoint : Transform; var AmmoSpeed : float; var X : float; private var x : float; function Start () { Ammo = transform; X = transform.localScale.x; } function Update () { if (!Attack) { gameObject.GetComponent(EnemyPatrol).walkSpeed = 0.02; gameObject.GetComponent(AnimateTexture).rowNumber = 0; gameObject.GetComponent(AnimateTexture).colNumber = 0; gameObject.GetComponent(AnimateTexture).totalCells = 14; gameObject.GetComponent(AnimateTexture).fps = 8; } else { gameObject.GetComponent(EnemyPatrol).walkSpeed = 0.0; transform.localScale.x = -X; gameObject.GetComponent(AnimateTexture).rowNumber = 0; gameObject.GetComponent(AnimateTexture).colNumber = 0; gameObject.GetComponent(AnimateTexture).totalCells = 14; gameObject.GetComponent(AnimateTexture).fps = 9; Ammo.transform.position = AmmoSpawnPoint; Ammo.position += Ammo.forward * AmmoSpeed * Time.deltaTime; } } Here is my code for the invisible box, which works fine i believe. #pragma strict function OnTriggerEnter(other : Collider){ if(other.tag == "Player"){ transform.root.gameObject.GetComponent(EnemyAttack).Attack = true; } } function OnTriggerStay (other : Collider) { if (other.tag == "Player") { transform.root.gameObject.GetComponent(EnemyAttack).Attack = true; } } function OnTriggerExit(other : Collider) { if (other.tag == "Player") { transform.root.gameObject.GetComponent(EnemyAttack).Attack = false; } } I am fairly new to coding, so if anyone could give me a few tips and tricks on how to do this.

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>