Performance Enhancing

Hey Guys,
I have just done a nice virtual gallery where if you fire at a painting it takes you to another"room"
I’ve got a few things like particle effects and some hi res wave files. (stereo16bit) Basically things are slowing down, and on my windows webplayer version, it even crashes. I have two questions:
Where are the sound files held during gameplay?-If I have a 50mb song and a 64mb video card, and the audio is temp stored on the video card, then Im in the stcky stuff, right? so theroretically reducing soundfile size will help(?)Maybe the audio is played from the webfile location, and not from the videocard?and therefore reducing audiofilesize wont change anything?
Q number2: How do I use the object destroy, -I have a shootball thing goin on, and my level fulls up with balls. If I use a timed object destroy script, when the designated time is reached, I cannot shoot any more balls. I really need the clones to have timed object destroy on them, not my source ball…

Just trying to get better performance, if anyone has any tips?
The school web browser filter has started blocking my visits to otee.dk so my call and response will be a bit slow. Thanks everyone.
AC

Audio should be in .ogg that will help size, and audio is not stored on the graphics card, thus the name. :stuck_out_tongue: I don’t think audio will affect performance at all, not really sure though. If it does its very little.

Bill

To destroy the clone instead of the original do something like…

theClone = Instantiate (theOriginal,transform.position,Quaternion.identity);
Destroy (theClone,time);

I imagine one single stereo audio shouldn’t be a big deal (no matter what the size), but if you had several audio clips/channels going at once I can see that starting to impede performance. But I bet that the fact that all your shooting objects are never destroyed is the reason you’re seeing a performance slowdown.

Hey thanks
I tried yer code, Antennas’ but to no avail. I assume its Java rather than boo or c#First it says some thing about “time” so I changed that to a value(2) then it says "Identity "is not part of Unity Quaterion, so I’ve tried changing Identity to sphere, no luck there, so Im stuck. Any tips?I just copy and paste the code you gave me and it should work?
Thanks in adv. :roll:

Firstly the APIs are same in both JavaScript and C#, the ony difference is in the syntax ans handling of types.

Secondly it’s Quaternion.identity (note, lowercase i). I have no idea why you substituded sphere instead.

Ok
If someone was dying I’d try to save them
Unless they were nasty b@#ards

Same w code -I’ll backhack it somehow

I made the adjustment
Now it says position is not a member of UnityEngine Transform
?

I bet it should just be spelled correctly :slight_smile: transform.position The original snippet has it spelled as “postion”

Ok freyr, typo fixed :wink:

Targos, the code snippet was just a generic representation of how to destroy the cloned object instead of the original. Check out the “Fire Projectile Explosion” scene in the “Script Tutorial” project to see a full explanation of how to destroy clones once they hit their target.

HTH

Ok cool. Its clear that not only that I need to learn code, but I want to…
Thanks Antenna, I will follow yr advice and have another swipe at the script tut. If anyone has a suggeston on a website where I can start learning code from the absolute beginner point of view, then that would be gratefully appreciated…
Getting to grips with code would be handy.
AC

Hey Targos,
I don’t have any good links for you unfortunately, I did a quick google on it and it is difficult to find JaveScript tutorials that aren’t web-oriented.

It is easier to find C# tutorials that are more easily applied to Unity, but I really don’t recommend you learn C# as your first ever programming language. JS is the way to go there.

You don’t need to learn the browser-specific stuff, just the basics of the syntax and how basic programming works. You can learn a lot by looking at other people’s code and trying little changes to see what they do. You don’t want to start out writing scripts until you can modify other people’s scripts effectively.

Good luck and don’t get discouraged…it’s worth it :wink:

-Jeremy

Jeremy-
Cheers-you know a little while ago I wouldve been content with pretty(3D and Interactive)pictures but now I need more. Im sure everyone who reads these forums has some version of that. So cheers for the encouragement, it does help. Im really into it too, its not like I feel I’m too thick to get it, I’ve just never been exposed to it. Now Im prepared to spend a long time to get really good at writing code, just as I couldnt build a level or firstperson shooter with unity a few months ago. Its really exciting. Ive just got to find a way to get stuck in, and revisiting the scripting tut is a start, if daunting to the beginner. At my training college it looks probable to develop our maya based animation into a game design course next year. A great leftbrain/right brain experience. Half modelling etc, half programming. We’ll be using Unity, so I’ll be showing potential tutors the scripting reference and as much code as I can find to give them an idea of what would be ideal to learn. My girlfriend is aching to move back to her home of Sydney but I have such a fantastic opportunity to stay here and learn Maya and Unity that shes prepares to wait…the Darling

Rock on guys, your help is valuable-I just wish scripting clues were helpful to me now rather than next year.-but please keep em coming! :stuck_out_tongue:

Hey, Targos.

I wrote you a tutorial, it got deleted with the other stuff when the forums crashed, but David posted a backup so I shall replace it.

I am glad you are willing to give coding a shot. In the words of a wise man; This stuff is just too cool to give up on. icon_wink.gif ¨

Here is the classic rotating cube script. You create a cube by clicking GameObject->Create Other->Cube, then you drag this .js script onto it.

Ok, first simply making the cube rotate:

function Update() 
{ 
  transform.Rotate(0, 10, 0); 
}

The first word “function” tells the compiler that the next code block is a function. Code blocks start with an { and end with an }.

So after “function” we have our function name “Update”. “Update” is a function that get’s called by unity every frame. Remember, case is important.

After our function name we have (). The () brakets are used to send data to the function if needed. Since we aren’t sending anything, we do (). Every function needs at least ().

Ok, We have finished telling the compiler that we have a function named Update that we are not sending any data to, now the next line is our {. Remember that { starts a function code block? The { is telling the compiler where your function code begins.

Next we have this line: transform.Rotate(0, 10, 0);
transform is a class is that manages the objects position, rotation, scale, etc. Since we are putting this script right onto our object, we just call transform. Next is a . and the word Rotate. Rotate’s first letter is uppercase because it is a function. After Rotate we have this (0, 10, 0). Remeber how I said the () are used to send data to a function? Well, here we are sending z,y and z to the function. The first number is the x axis, we set it to 0 because we don’t want to rotate on the x axis. The next number is the Y axis, and we set it to 10. 10 units per frame. Next is Z, and again we set it to 0. We just told the Rotate function to rotate around the Y axis (the middle number) 10 units per frame.

Right after the transform.Rotate line is “;” The semi colon is put at the end of most code you write. Take a look at other people’s code to see where it is used and where it isn’t.

Next comes the }. That closes the function code block, it tells unity that you have finished writing your function code.

So when you put the script on a cube and hit play, the cube will rotate.

But, what if we rand the code on a super slow machine? Since it is rotating 10 units every frame, wouldn’t lower framerates cause the cube to rotate slower? Yes it would. But there is a fix:

function Update() 
{ 
  transform.Rotate(0, 10 * Time.deltaTime, 0); 
}

We multiplied (*) 10 by Time.deltaTime. Time is a class that provides…you guessed it, time functions. Time.deltaTime is float (number with a decimal point: 1.5, 2.333452) that contains the amount of time that has passed since the last frame. So by multipliying our speed number, 10, by Time.deltaTime, we ensure that the cube will spin at the same speed regardless of framerates.

Now try making the cube rotate on another axis, ot two at once.

I wish I could write more, but I have to get back to programming myself.

HTH,
-Jeremy
PS: Thanks for the backup David. :wink:

Hey Jeremy I just backtracked on the dumped server files and found your post-Thanks heaps man, thats absolutely wicked.
I know it must have taken you a wee bit of time to write that, and I appreciate it. I will apply it ASAP. I look forward to trying it on a sphere colliding sphere, so it randomly rolls across the land…Theres prob a few things to learn, ie the transform function may conflict with the physics equations of moving across a landscape…I’ll let you know…Thanks againAC

Moving an object by transform.Rotate just rotated the object, it does nothing with physics. If you wanted to make a sphere rolling across the ground you woula need to attach a rigidbody to the sphere, and write a script that applies torque. I highly recommend that you take your time learning the basics (like the example I just posted) before you jump ahead.

Try the tut I posted, then try to make the cube move using Transform.Translate(x,y,z) instead. Then try adding your own variables (var mySpeed = 10; ) and so on. Jumping ahead will get frustrating quickly belive me.

Good luck,
-Jeremy

[quote]
Then try adding your own variables (var mySpeed = 10; ) and so on. Jumping ahead will get frustrating quickly belive me.
[/quote]I

Cool I got the rotate and translate functions happening. Can you show me how(where in the script) to put the above “Var” part into it?
Thanks
AC

var mySpeed = 10;

function Update()
{
  transform.Rotate(0, mySpeed, 0);
}

Have fun :wink:
-Jeremy

var mySpeed = 10; 

function Update() 
{ 
  transform.Rotate(0, mySpeed * Time.deltaTime, 0); 
}

Using Time.deltaTime will also make the script independent of framerate, so it will rotate at the same speed no matter how many frames per second the machine is rendering with.

Heh, thanks Joe. I forgot to add that from my first example.

-Jeremy

Very Cool.Thanks. Got it.
So a varible(var) is always at the very beginning?

After our function name we have (). The () brakets are used to send data to the function if needed.[quote]

[/quote]

What kind of data could be sent to the function?as in, what could exist inside these brakets

I think Im getting it- :shock:
AC