private static void setupCustomFireballObject(redwing_fireball_behavior behavior, BoxCollider2D collide, GameObject fireballSprite, float xVelocity, float yVelocity) { behavior.fireball = fireballSprite; collide.isTrigger = true; behavior.selfTranform = behavior.gameObject.transform; behavior.fireballSprite = fireballSprite.GetComponent <SpriteRenderer>(); behavior.fireballPhysics = behavior.gameObject.GetComponent <Rigidbody2D>(); collide.size = behavior.fireballSprite.size; Vector2 spriteSize = behavior.fireballSprite.size; //collide.offset = new Vector2(spriteSize.x / 2, 0); collide.offset = new Vector2(0, 0); behavior.rotationalVelocity = (float)((redwing_flame_gen.rng.NextDouble() - 0.5) * 10.0 * 180.0 / Math.PI); behavior.xVelocity = xVelocity; behavior.yVelocity = yVelocity; behavior.hitboxForPivot = collide; behavior.fireballMagmas = fireballMagmas; behavior.doPhysics = true; behavior.fireballMagmaFireballs = fireballMagmaFireballs; behavior.fireballMagmaFireballHeight = redwing_flame_gen.FBMBTEXTURE_HEIGHT; behavior.fireballMagmaFireballWidth = redwing_flame_gen.FBMBTEXTURE_WIDTH; behavior.cachedAudioPlayer = fireballSprite.GetComponent <AudioSource>(); }
public static void addSingleFireball(float xVelocity, float yVelocity, float xTransform, float yTransform, string nameExtend) { if (voidKnight == null) { return; } GameObject fireballSpawnPoint = new GameObject("redwingFireballSpawner" + nameExtend, typeof(redwing_fireball_spawner_behavior)); Vector3 fbSpawnPos = voidKnight.GetComponent <BoxCollider2D>().bounds.center; fbSpawnPos.y += 0.4f; fireballSpawnPoint.transform.position = fbSpawnPos; fireballSpawnPoint.layer = 31; fireballSpawnPoint.SetActive(true); GameObject fireballPivot = new GameObject("redwingFireball" + nameExtend, typeof(BoxCollider2D), typeof(Rigidbody2D), typeof(redwing_fireball_behavior)); fireballPivot.transform.parent = fireballSpawnPoint.transform; fireballPivot.transform.localPosition = Vector3.zero; fireballPivot.layer = 0; GameObject fireballSprite = new GameObject("redwingFireballSprite" + nameExtend, typeof(SpriteRenderer), typeof(AudioSource)); fireballSprite.transform.parent = fireballPivot.transform; fireballSprite.transform.localPosition = Vector3.zero; // Layers 20, 9, 26, and 31 are explicitly ignored by the game // and layers above 31 don't exist // set to layer where it won't be treated like an enemy. fireballSprite.layer = 31; setupFireballSprite(fireballSprite.GetComponent <SpriteRenderer>()); setupFireballPhysics(fireballPivot.GetComponent <Rigidbody2D>()); setupCustomFireballObject(fireballPivot.GetComponent <redwing_fireball_behavior>(), fireballPivot.GetComponent <BoxCollider2D>(), fireballSprite, xVelocity, yVelocity); redwing_fireball_behavior b = fireballPivot.GetComponent <redwing_fireball_behavior>(); Vector3 selfPos = b.selfTranform.position; selfPos.x += xTransform; selfPos.y += yTransform; b.selfTranform.position = selfPos; b.selfPosition = selfPos; // just some basic algebra/calc to get the expected height using Newton laws. //double maxXPoint = 3.0 / (yVelocity); //b.maxHeight = (float) ( (-1.5 * Math.Pow(maxXPoint, 2.0)) + yVelocity * maxXPoint); b.realisticPhysics = true; fireballPivot.SetActive(true); fireballSprite.SetActive(true); }
private void setupCustomFireballObject(int i) { redwing_fireball_behavior behavior = fireballPivotGOs[i].GetComponent <redwing_fireball_behavior>(); BoxCollider2D collide = fireballPivotGOs[i].GetComponent <BoxCollider2D>(); float xVelocity; float xTransform = 0f; switch (i) { case 0: xVelocity = 0f; break; case 1: xVelocity = 1.666f; xTransform += 1f; break; case 2: xVelocity = -1.666f; xTransform -= 1f; break; case 3: xVelocity = 3.333f; xTransform += 2f; break; case 4: xVelocity = -3.333f; xTransform -= 2f; break; case 5: xVelocity = 5f; xTransform += 3f; break; case 6: xVelocity = -5f; xTransform -= 3f; break; default: xVelocity = 0f; break; } const float yVelocity = 30f; setupCustomFireballObject(behavior, collide, fireballsGo[i], xVelocity, yVelocity); Vector3 selfPos = behavior.selfTranform.position; selfPos.x += xTransform; behavior.selfTranform.position = selfPos; behavior.selfPosition = selfPos; }