Pular para o conteúdo principal

Basic Circle Chain Engine Using Unity3D Part 3

What we need to do in this third part:

. RedBullet collides with GreenCircle.

. GreenCircle spawn GreenBullets.

. repeat the process each collision between "bullets" objects and GreenCircles.

Basically we need add physics components to GameObjects, then add colliders.

1. In the prefab folder, select RedBulletPrefab. In the Inspector panel, at bottom, click the button Add Component > Physics > Rigidbody. Then uncheck "use gravity", check "Is kinematic" and I checked too the z position and x, y, z rotation freeze options.

1. Rigidbody

1. Rigidbody Config

2. With RedBulletPrefab selected, add a new physics component, collider. For bullets I choose Box Collider, for the Green Circle I added an Sphere Collider. Just check "Is trigger" since we will use C# script to control collisions. 

2. Colliders

2. Colliders Config

3. Do the steps 1 and 2 above to GreenCirclePrefab.

4. Let's create a new prefab, GreenBulletPrefab. It's based in the RedBulletPrefab, so drag and drop RedBulletPrefab into Hierarchy panel. Rename to GreenBulletPrefab. Go to Texture folder and assuming that you have already imported the greenbullet.png (Texture type: advanced, uncheck generate mip maps, filter mode: point), drag and drop into the new GreenBulletPrefab. Then drag and drop GreenBulletPrefab to the Prefab objects. Now you can delete GreenBulletPrefab from Hierarchy panel, since we will instantiate this object with C# script.

4. Prefabs done

5. Open the CircleChain script in the Script folder. Here we need check for collisions and spawn the green bullets, then destroy the green circle object. Basically we will add this: 

// prefab to be instantieated

public GameObject greenBulletPrefab;

public float greenBulletXSpeed;

public float greenBulletYSpeed;

public float bulletSpeed = 3;

 

...

 

// check for collisions

void OnTriggerEnter(Collider obj) {

// for debug

//print(obj.gameObject.name);

 

// if this object collides with the red/green Bullet

if (obj.gameObject.name == "RedBulletPrefab(Clone)" || obj.gameObject.name == "GreenBulletPrefab(Clone)") {

 

// calc the new bullets positions

for (int i = 0; i < 4; i++) {

 

// calc the direction of the bullet

greenBulletXSpeed = bulletSpeed * Mathf.Cos(i * Mathf.PI / 2); //redBullet.xSpeed=bulletSpeed*Math.cos(i*Math.PI/2);

            greenBulletYSpeed = bulletSpeed * Mathf.Sin(i * Mathf.PI / 2); //redBullet.ySpeed=bulletSpeed*Math.sin(i*Math.PI/2);

 

// create a instance of bullet (green)

GameObject clone = Instantiate(greenBulletPrefab, transform.position, transform.rotation) as GameObject;

clone.SendMessage("setBulletXSpeed", greenBulletXSpeed);

clone.SendMessage("setBulletYSpeed", greenBulletYSpeed);

 

}

// after all, destroy the green circle

Destroy(this.gameObject);

}

 

}

 

We used this for our RedCircle script.

Thats it!

Done!

Download here the new complete project files: http://goo.gl/TgBehj

Just open the "scene03" in the scene folder.

Comentários

Postagens mais visitadas deste blog

Gamasutra's Postmorten: RiverMan Media's MadStone

Aqui vão os meus comentários sobre este postmortem. O jogo em questão, MadStone, foi desenvolvido para a plataforma WiiWare, vindo de um antigo sonho de publicar um jogo para Nintendo (dos fundadores da RiverMan). MadStone é um puzzle 2d, onde as peças vão caindo (assim como tetris) e que custa U$8.00 no WiiWare. Antes de publicar um jogo para WiiWare, a desenvolvedora havia já desenvolvido outros dois jogos casuais para PC, Cash Cow e Primate Panic. Tela do jogo MadStone Bom, vamos às dicas deixadas pelos desenvolvedores: O que funcionou: 1. Correr atrás da Nintendo: Entre contatar a Nintendo e se tornar um desenvolvedor autorizado, os desenvolvedores tiveram que correr um pouco atrás. A primeira lição é justamente essa, não é fácil correr atrás e muitas vezes temos que sair de nossa zona de conforto para conseguir as coisas. 2. Plataforma 2D: A decisão de desenvolver um jogo 2D foi tomada por algumas facilidades como ferramentas de arte mais simples, como o photoshop; Pouco código

Converter campo text para varchar – SQL Server 2000

Outro dia, conversando com um analista de sistemas no trabalho, este me perguntou, qual era melhor, usar o tipo text ou varchar no campo. Bom, baseado em minhas experiências, respondi que prefiro trabalhar com varchar. Mas antes, uma breve pesquisa no google nos mostrou que: text     Variable-length data with a maximum length of 2^31 - 1 characters varchar Variable-length data with a maximum of 8,000 characters fonte: Database Journal Depois de analisarmos o propósito a que o campo serviria, decidimos por um campo varchar(500). Se você, assim como eu, tentou utilizar uma alter table, alter column, deve ter visto um aviso do SQL Server de que isto não é possível de se fazer. Mas e agora? É isso mesmo que pensamos: temos que criar o novo campo e popular com o que havia no antigo campo. Exemplo: EXEC sp_rename 'tab_inf_nota.mensagem', 'mensagem_old', 'COLUMN'

My fist job @ game industry!

Yes, yes and yes! I have no words to describe this! Awesome, hot, wild! So, what I did? Work as Game Tester for  @LowpolyStudios The game Blowing Pixels Planet Defender for #iPhone was sended to Apple Store review in August 17 and is expected to launch in August 29, so stay tunned! Blowing Pixels Planet Defender, or just BPPD, is a Defender kind game, so you have to break the enemies invasion. Actually, this game is so addictive, like play Tetris! Your brain will enjoy, hwar, hwar, hawr... You can see more details @ developer's web sites: http://www.lowpoly-studios.com/ http://www.facebook.com/LowpolyStudios http://twitter.com/#!/lowpolystudios http://www.blowing-pixels.com/planet_defender.php Oh! Yeah, the Credit Screen: I'm in Testers part: ALEX CANCADO. So, fuck'n YEAH! Next related post I will write about how I get in touch with developer and my contribution about the game.