Quantcast
Viewing all articles
Browse latest Browse all 1488

Game 2x speed object pass through other

I am making a basic TD game with a fast-forward feature. When i press the fast-forward button, the game speeds up, but the bullet that the turret shoots goes through the enemy (object). This is the code for the bullet:

void OnTriggerEnter(Collider other){

		//-- Development Test

		if(Time.timeScale == 2){//If fast forward
			if(other.tag == "Enemy" || other.tag == "Enemy 2"){//if hit enemy
				Time.timeScale = 0;//pause game
				Debug.Log (other.collider.gameObject.name);//Debug enemy name
			}
		}
		//--
		
		if(other.tag == "Enemy" || other.tag == "Enemy 2"){//if hit enemy
			other.collider.gameObject.GetComponent().setHealth (Damage);//reduce health
			Destroy(gameObject);//destroy bullet
		}
	}
And this is how the turret aims:

if(myTarget){//if turret has a target

			if(Time.time >= nextMoveTime){
				//CalculateAimPosition(myTarget.position);
				turretBall.LookAt(myTarget);//lookat the target
			}
			if(Time.time >= nextFireTime){//if can fire
				FireProjectile();//fire bullet
			}
		}
In the Development Test section (of the bullet script), the bullet doesn't "collide" with the enemy (or it doesn't detect it). How would i detect if the bullet collides with an enemy when the game is at 2x the speed?

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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