Nov
13
2013

Convert old project to 2D physics & Sprites

sprite_renderer_unity

Started converting this shootemup test into Unity 4.3 2D physics ( old: http://unitycoder.com/blog/2013/09/27/shoot-em-up-proto-unity/ )

Webplayer: (using new 2D physics & sprites, no collider on player yet)
http://unitycoder.com/upload/demos/Shmup3_2D/

Some conversion notes so far:

SHMUP TO 2D SYSTEM

Lets test..

2D viewport Enabled!

Camera:

–          Setup Camera for Pixel Perfect graphics: http://forum.unity3d.com/threads/210329-Unity-4-3-Tips-amp-Workarounds?p=1415249&viewfull=1#post1415249

Player:

–          Rename old “PlayerShip1” to “PlayerShip1Old”, disable it

–          Take player ship image, set its type to Sprite

–          GameObject / Create other / Sprite

–          Rename this gameobject as “PlayerShip1”

–          Copy my playercontroller script component to this “PlayerShip1”

–          Adjust speed (it was 255, now 3 is enough, since sprite is 1×1, instead of 64×64)

–          Add 2 empty gameobjects as child,  for GunPivot and LaserPivot, and position them

–          Assign those pivots to playercontroller script variables

–          Set gameobject Tag & Layer

–          Create new prefab from “PlayerShip1” (drag it to project folder)

Player Bullets:

–          Take our bullet image, set its type to Sprite (default settings as above)

–          GameObject / Create other / Sprite

–          Rename this gameobject as “SpriteBullet1”

–          Copy my bulletcontroller script component to this “SpriteBullet1”

–          Create prefab from this “SpriteBullet1”

–          Assign that prefab to playercontroller as a bullet prefab

–          ** something happened, sprite (image) is missing from the prefab **

–          Lets assign the bullet image(sprite) to it again from assets

–          Old bullet had box collider & rigidbody..

–          So lets add BoxCollider2D and RigidBody2D

–          Adjust BoxCollider2D size

–          Set Rigidbody2D gravityscale to 0 (it was 1, and bullet was falling down..)

–          Old bulled was moved with transform.Translate() inside Update(), remove that.

–          So lets try just RigidBody2D.Velocity after instantiate, just add 1 line (and 1 speed variable)

 clone.rigidbody2D.velocity = Vector2.right*bulletSpeed;

–          Set bullet gameobject Tag & Layer

–          Bullets are colliding to eachother..

–          Need to set Project Settings / Physics2D / Layer Collision Matrix (I had set these for Physics also, for not allowing player bullet to player bullet collisions)

Enemy:

–          Take our bullet image, set its type to Sprite (default settings as before)

–          GameObject / Create other / Sprite

  • Note: If you have that sprite already selected, it will be assigned to this sprite gameobject

–          Rename this gameobject (sprite) as “Enemy1”

–          Copy my enemycontroller script component to this “Enemy1”

–          Old enemy had box collider and transform.Translate() movement

–          Lets add BoxCollider2D

–          Adjust BoxCollider2D size

–          Set “Enemy1” gameobject Tag & Layer

–          ** hmm bullets collide to enemy, but wont do any damage.. **

–          Ok, had to replace this line in bulletcontroller:

void OnCollisionEnter(Collision collision)

with:

void OnCollisionEnter2D(Collision2D collision)

–          Adjust explosion particle system size to smaller


12 Comments + Add Comment

Leave a comment

Connect

Twitter View LinkedIn profile Youtube Github Join Discord Twitch Instagram BlueSky

UnityLauncherPro

Get UnityLauncherPRO and work faster with Unity Projects!
*free unity hub alternative

@unitycoder_com

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.