x


prefab billboard with a transparency texture?

I'm on my unity (iPhone) learning curve and working on a arcade shooter game...

I want to use a billboard/sprite prefab for weapon projectile. I will instantiate this prefab when the player presses the fire button.

I would like the prefab to have the following characteristics:

  • use a sequence of tga files (named X0001.tga, X0002.tga, X0003.tga, etc) to create an animation
    • I want to use tga files for transparency but if better option pls suggest
    • I want control over the "frame rate" for the tga files
  • The billboard should always face the camera.
  • I will use transform.position to move the projectile in the direction fired

Not finding much documentation on creating a billboard (sprite) based prefab but perhaps I not searching correctly.

Can someone point me to documentation or provide some guidance? Thanks for any help!

more ▼

asked Sep 07, 2010 at 04:06 AM

RSud gravatar image

RSud
211 71 54 65

This is not appropriate for this website. Put it on the forum.

That said, you do NOT want to use a sequence of files; you want to use a single texture and change the offset on it.

http://forum.unity3d.com/viewtopic.php?p=276656

Sep 07, 2010 at 04:35 AM Jessy

@Jessy I'm not sure why you think this form of question is not appropriate here. It could be more focused sure, but it's not completely open or vague and fits okay into the framework on this site.

Sep 07, 2010 at 11:11 AM runevision ♦♦

I agree, the question seemed appropriate enough. I would have given some basic billboarding information in my response.

Sep 07, 2010 at 11:16 AM qJake
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Make a billboard mesh to use for your object and use a script with Transform.LookAt to make it look at the camera in every Update.

As for doing sprite animation, search for sprite animation. (You'll probably find that putting all the animation frames into a single texture and using UV offsets to animate is a more common method to use than using separate images.)

more ▼

answered Sep 07, 2010 at 11:01 AM

runevision gravatar image

runevision ♦♦
9.3k 55 114 256

(comments are locked)
10|3000 characters needed characters left

This assumes you've put everything onto a texture atlas and you have 64 frames of animation... I wrote this while mildly drunk, and you'll need to put a transform.LookAt(camera.position) sort of dealio on it. I'm sure you'll figure it out :)

You could easily make this work with any number of frames.

private var frame = 1; private var xOffset = 0.0; private var yOffset = 1.0; private var waterMat : Material; private var on = true; function Start() { animWater(); }

function animWater() { while (on) { // Offset the X xOffset += 0.125;

     if (xOffset>0.99) // if it goes over one, return carriage :P
     {
         xOffset = 0.0;
         yOffset -= 0.125;   
     }

     if (frame>62) // Max number of frames reached
     {
         xOffset = 0.0;
         yOffset = 1.0;  
         frame = 0;
     }
     frame ++;

     renderer.material.mainTextureOffset = Vector2(xOffset,yOffset); 
     yield;
     }

}

more ▼

answered Sep 07, 2010 at 01:46 PM

jtbentley gravatar image

jtbentley
639 8 10 27

I almost follow... but I'm still early in my learning curve.

You have the line:

renderer.material.mainTextureOffset = Vector2(xOffset,yOffset);

What is 'render'? is this billboard object?

Sep 08, 2010 at 12:40 AM RSud

Renderer is the component that actually draws it, so i'm offsetting it per frame. You can specify a seperate renderer if you use a variable for it up top..

var rendererToOffset : Renderer;

then..

rendererToOffset.material.mainTextureOffset = Vector2(xOffset,yOffset); // Better anyway because it removes get_component calls which are slow

Sep 08, 2010 at 03:55 AM jtbentley
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x7064
x2192
x1170
x108

asked: Sep 07, 2010 at 04:06 AM

Seen: 6488 times

Last Updated: Sep 07, 2010 at 04:06 AM