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...

GameDev Tutorial - Basic Circle Chain Engine Using Unity3D Part 1

Circle Chain ( http://www.emanueleferonato.com/stuff/circle_chain/ ) is a simple game developed in 2007 by Emanuele Feronato ( http://www.emanueleferonato.com ) as a monetization test in Flash Games. In fact it's based on Boomshine ( http://www.k2xl.com/games/boomshine/ ) Emanuele has since, ported his game tutorial for lots of platforms: AS3: (complete)  http://www.emanueleferonato.com/2012/02/20/circle-chain-ported-to-as3-with-commented-source-code-available-ready-to-jump-to-the-iphone/ Game Maker: (basic)  http://www.emanueleferonato.com/2012/06/07/circle-chain-engine-made-with-game-maker/ Construct2 HTML5:  http://www.emanueleferonato.com/2012/03/14/html5-version-of-circle-chain-engine-using-scirras-construct2/ Corona SDK:  http://www.emanueleferonato.com/2012/02/24/basic-circle-chain-engine-using-corona-sdk/ Gideros Studio:  http://www.emanueleferonato.com/2012/04/12/basic-circle-chain-engine-using-gideros-studio/ Stencyl:  http://www.emanueleferonato.com/2012/02/29/ba...

Replicação coluna Text – SQL Server 2000

Hoje no trabalho, a pedido de um analista de sistemas, coloquei para replicar uma tabela. Eis que, depois de tudo pronto e configurado, no monitor de replicação do enterprise manager, tenho uma mensagem de erro na replicação, pois não é permitido update de coluna text junto com um index clustered. Agora mais essa, o SQL Server todo dia me prega uma peça. Bom, consultando meus caros colegas de trabalho pelo google, não encontrei nenhuma solução real para o problema, na replicação. Algumas soluções encontradas eram tirar o índice clustered e tentar update um por vez, dos campos. Bom resolvi usar minha própria solução: tirar a tabela da replicação, mudar a maldita coluna text para varchar e colocar para replicar novamente. Como a tabela já era populada e nunca havia tido a necessidade de replicá-la, tive que descobrir qual o tamanho máximo que algum registro da coluna text estava utilizando: select max(len(convert(varchar(8000),mensagem))) from base..tabela Varchar(8000) é por ...