u3d movedolocalmovez 谁的z轴

手机签到经验翻倍!快来扫一扫!
山寨高仿 刷机包 汇总
19382浏览 / 700回复
& & & & & & & & & & & & & & & & & & & & & & & & &山寨高仿 刷机包 汇总&卡刷包1:链接: /s/1pbuVL 密码: rheb卡刷包2 & 链接: /s/1gTRKV 密码: sprq卡刷包3 &链接: /s/1h9OOT 密码: 7h8h卡刷包4 &链接: /s/1vMVuu 密码: v9ss卡刷包5 &链接: /s/1w2UCW 密码: 0yyr卡刷包6 &链接: /s/1rJm37 密码: 23te卡刷包7 链接: /s/1AGeYT 密码: y5gv卡刷包8 链接: /s/1pHueI 密码: fwwa卡刷包9 链接: /s/1GfJaL 密码: igxu卡刷包10链接: /s/1xORhM 密码: ysyg本帖隐藏的内容需要回复才可以浏览
正好有着需要
正好有着需要
要下载了才知道能不能用
看看有用否
谢谢,下来试试
谢谢,下来试试
很需要,谢谢楼主分享
谢谢主,看能不能用
楼主,每个都看过了,就找到9502的啊,既然做好事,为什么不写清楚一点嘛。
感谢lz无私奉献
就能解决您解决哦贫农哦 你
感谢感谢感谢感谢感谢感谢
很好的都很好 房间内飞好减肥 计划花费
这个必须要顶啊
支持键盘翻页 ( 左右 )&
您需要登录后才可以回帖&&&|&&&&&
用户名/注册邮箱/注册手机号
其他第三方号登录How to do Lasers in&Unity3D
I was recently asked about how the lasers were done in
and I’d said I’d blog about that and a few other items, so here’s the first of a few.
This is the same material I covered at Unite 2009, so if you’ve seen the video or were there, there’)
Here we’ll cover one way of doing lasers with Unity3D that looks good and is performance friendly for the iPhone.
This isn’t meant to be exhaustive by the way, it’s just meant to be the base overview of what a laser *is* in Unity and how I managed it in terms of performance for the iPhone game.
So with that, let’s jump in to some steps on setting it up.
Create LineRenderer
0. First, Create an empty GameObject in your scene.
Then, attach a line renderer component to your GameObject and position the GameObject where the tip of the laser cannon will fire from.
Why not just use a particle emitter?
This is because the ellipsoid particle emitter has a bug.
even if you set the size of the ellipsoid to 0 on all 3 axis or .0001, you will see that it starts at a random location on the z axis.
Unity acknowledged the bug.
So to fix this, since we can’t emit using the particle emitter from the cannon’s tip, we have to first show a line renderer.
Below are some typical settings you could use for a LineRenderer as a laser bolt:
Properties of a general LineRenderer for a laser
Here’s what it should look like in the Unity IDE when you get your GameObjects in place:
GameObjects with LineRenderes placed at the cannons
I created a class called LaserControl, and when I want it to show, this is literally what I do:
public var isShowingLaser:boolean =
function showLaser()
if( isShowingLaser )
isShowingLaser =
thisRenderer.enabled =
yield WaitForSeconds (.05);
resetLaser();
isShowingLaser =
as you can see, it shows it for .05ms then hides it by calling reset laser which just does this:
function resetLaser()
this.renderer.enabled =
So, then create your own class that extends MonoBehaviour and attach it to the GameObject that you added the LineRenderer to.
Create Particle Emitter
Now that we have this really nice LineRenderer laser that looks great coming from the tip of the cannon, we actually need to emit a laser to “fly” on it’s own path, right? So the concept for this is:
create empty GameObjects to server as 3D points for your emitter to “jump” to when you when it is to emit a laser from a particular cannon.
Since a particle emitter counts as 1 draw call for all of its particles, this makes it especially nice on an iPhone build.
Even better, it’s very lightweight on a web based game.
Create 1 new GameObject for every cannon you have.
In this instance, I had 4 for the X-Wing, so I created 4 GameObjects with nothing in them.
Then give them names like TL, TR, BL, BR (topLeft, topRight, bottomLeft, bottomRight).
Here’s a screenshot of one of the emitter locations highlighted in the editor:
Empty GameObject serves as location for emitter later on
Position these new GameObjects at the very end of the LineRenderer in your scene.
These will be the location that the emitter jumps to just before being told to Emit(1).
Now, create a GameObject.
Then, with that GameOject selected, add: 1) Ellipsoid Particle Emitter, 2) Particle Animator, 3) Particle Renderer.
In Particle Ellipsoid Emitter, set Local Velocity & z = -500.
This is the speed essentially.
If you want a faster laser, increase the number.
Make sure “Simulate in worldspace” is checked as this will allow emitted particles to carry on their path in world space once they’re fired.
Set the Ellipsoid to 0 on all 3 axis.
Finally, set Min Emitter Range = .0001 to make sure it fires from the closest location to the center of the GameObject as possible.
Like I said, with the bug, it’s a bit random on the z axis, but you’ll never see that in the game.
Leave the Particle Animator as is.
Now the other bit of magic in making the laser is the Particle Renderer.
You’ll want to set “Stretch Patricles” = Stretched, with a length scale of 7 or so.
You can play with this number as it will determine how good your bolt looks in length.
Then set the “Max Particle Size” = .01.
Here’s a screen shot of the settings for the particle emitter and renderer ( the animator is left with its defaults ):
Particle Emitter settings
Conclusion
At this point, you have the physical objects in your scene to manage your lasers.
The last remaining step is to write a class that moves the emitter to each of those 4 emitter location GameObjects, tells the LineRenderer to show() and then emit 1 particle – BAM!
You now have lasers in Unity!
Hope this helps and hope you have a Bandit day ?
[tweetmeme source=”neoRiley” only_single=false]
Advertisements
Share this:
TrackBack URL
Connecting to %sUnity’s a beast. I’m always impressed at how versatile and performant it can be. But like any beast it requires a little bit of taming (and in some cases some very counter intuitive trickery, but that’s where this metaphor falls apart). I’ve had a bit of a struggle getting Truck Toss to play smoothly on my 3GS, but here’s a nice big list of tips to help you on your way.
If this is your first jump into the world of Unity, my first tip (this one’s a freebie) is to stop trying to use it like other languages and environments. You will be using GameObjects, you will be adding multiple script components, and you will have to think differently. When I first started, my approach was to largely ignore prefabs (or use them like Flash’s display list) and get a copy of Box2D running. Painful as it is to deviate, get ready to put in some work!
Without further ado, let’s get started:
-Use the built-in physics.It might seem like a waste of cycles to have a fully 3D physics engine running the show for a 2D game, but bear in mind that the Nvidia PhysX engine will be running in Unity’s native core. We’re talking about a hyper-optimised engine maintained by large professional teams, and not a hobbyist 2D engine. Freeze Z position and X/Y rotation for that 2D feel.
-Try to use a 1/1 scale. By this I mean, 1 unit = 1 meter.
You can use larger or smaller scales, but you’re likely to encounter some weirdness when it comes to collisions, and the speed at which objects fall. Remember, a grand piano without air resistance will fall as fast as a dead baby but if everything is large, it will seem slow. You can fiddle with gravity, but again, you’re running the risk of messing with collisions. I like to use a 1/32 scale compared to my sprites with a cam size of 160.
-Get your object Mass right. Just like with scale, if you have a grand piano weighing 2gm or a dead baby weighing 500kg things are going to get unpredictable. Try to keep it realistic-ish.
-Mesh colliders can be slow compared to primitive box/sphere colliders. While a sphere may have many more verts than say a cube, the uniform distance from the centre would make it massively easier to calculate than lots of individual triangles.
-You can simulate more complex shapes by combining primitive colliders. If you have a parent object with say a Box Collider and Rigidbody component, you can add child objects with just a Box Collider. The entire object will collide like one solid multipart object.
-Continuing from the above… Rather than having several of these linked together, you can add more child objects with RigidBodies and Colliders, and use Joints to connect them to the parent object. You could build a compound car for example with a parent body to move the entire thing.
-Multiple basic joints are not supported on one game object… …but multiple configurable joints are. Rather than having a network of jointed objects you could for example have a spring and a slider from wheel to axle cutting down on a suspension object in between.
-Objects with a collider but no RigidBody are considered static. Moving these is expensive, so if you’re creating them with code, add the collider and physics material (to the collider) after positioning.
-While it’s considered good practice to keep your solver iterations constant……you might find it beneficial to use the full amount only every 2nd update. I.e.
8,4,8,4,8,4. If this alleviates some of the processor load the solver for example may not have to skip iterations, and will actually provide a more consistent simulation. I said it was going to be counter-intuitive.
-While the use of Interpolation and Extrapolation on RigidBodies is discouraged en-masse..…in some cases you might find that turning these on, and reducing the overall solver iterations provides a better simulation. Fiddle.
-Lower your timestep! If you’re aiming for an unrealistic 60FPS and the phone is constantly struggling, you’re best just to settle for a lower framerate and give it some breathing room. I like to use a 0.03 fixed timestep with a maximum of about 0.05. Again, it can be slightly counter intuitive decreasing timesteps to get higher framerates, but give it a shot.
-Timescale scaling.This could help, depending on the feel your’e going for. It simply simulates more time passing between each iteration. Setting this too high will obviously mess with collisions, especially if an object has traveled say, a mile in one frame, it’s not going to hit a damn thing.
Sprites & Textures
My engine uses a hybrid system of Sprite Manager2/EZGUI and RageSpline for sprites, but I’ve used 2D Toolkit and much of the following still applies.
-Easy on the fill rate! It might seem obvious but if you have a 64×64 image, with only the top left 32×32 filled, that’s still a 64×64 sprite. Trim your transparent images where possible. Lots of libraries will do this automatically.
-Hide sprites you’re not using. Make a reference to them and set them active = They won’t be drawn when offscreen anyway, but something has to determine whether or not they’re visible and chances are you know best, especially when one sprite may be fully hidden behind another and is still drawn.
-Batching is your friend. But not always. If you have 40 collectable coins in your level, all using the same sprite then batching will use the one texture source multiple times on a
giant mesh, saving on draw calls. Draw calls=time. In some very rare cases the batch calculations can be a hinderance, depending on how your game’s set up, but if that’s the case, chances are you’re doin’ it wrong.
-Resize your sprite’s Quad (the sprite itself) rather than its transform. If you have say a sprite component on a GameObject, then resize the GameObject’s transform, you’re going to break batching on that sprite. Instead consider the next point. With SM2 for example, you’d just set the Sprite/PackedSprite’s “Width” and “Height” properties in the inspector.
-If you have a 64×64 sprite, on a 6px wide cube… …then it’s going to look like a small version of your image, but upon zooming in, you’ll see that the full 64×64 sprite has been UV mapped to the cube in perfect detail. Remember what I said about fill rate. Unless your’e zooming in and out, you might not want to use such a large texture.
-Use a Sprite Sheet/Atlas where possible. This one ought to go higher, but what the hell. A sprite sheet will allow you to use commonly grouped items like your character, coins, platforms, etc in a single image/texture. Why? Less draw calls! The same part of a texture can be UV mapped to different parts of a 3D shape multiple times. I.e. if you were modelling a red and white stripy candy cane, you’d draw one white and one red line, then apply them multiple times. This is a similar concept.
-Use the right shaders! There’s no point using lit shaders if you’ve no lighting, and there’s no point using a transparent shader on a solid square sprite. You can find dedicated mobile shaders in the Unity Store, by googling and doing a little copy-pasta via MonoDevelop or using those that come with SM2/Unity. As of 3.5 I believe the default shaders do a pretty decent job. Coming from various other backgrounds it might be easy to underestimate the importance of these even in a 2D environment.
-Do you really need antialiasing/filtering on your sprites? Be sure to check on your target device. Some things will look pretty horrific scaled up on your monitor, but absolutely fine on those tiny high-density screens. Give it a shot, and remember to apply changes to your Sprite Atlas where possible.
-Easy on the compression! DXT (DirectX) compression will do a fantastic job on your PC, with hardware decoding, but mobile devices lack this hardware decoder and will have to do it in software. I.e. Slowly. Generally IOS devices will support hardware PVRTC compression and Androids ETC, and keep in mind what I said in the last point. DXT might be fine given that it offers better clarity during say level loads, but you certainly don’t want to be decompressing them during gameplay.
-Do you need Mip Maps? Mip maps are scaled down versions of a texture stored within the compressed texture itself. So depending on how far away you are, a lower res copy can be used. Obviously this takes more memory and more decompression time. You probably don’t need ’em for a 2D game.
-Conversely……rather than using giant sprites on a non retina display and tiny sprites on a
retina display, it might be worth your while making a small and large version of textures and using each accordingly.
-Read/Write enabled textures generate a second copy. Second copy needs more memory. In most cases, you can just leave this turned off.
-Tinting a sprite will break batching… …and create a new copy of the source texture in memory. Avoid where possible, or try to pre-make any colors you’ll need! E.g. if all your Numbers in a text sprite sheet are to be red.. do it in photoshop.
Loading, Saving and Object Access:
-Do you really need to recreate your GUI for each level? You can hide it and have it persist when loading different scenes, reducing loading time.
-GameObject.Instantiate() is slow! One common technique (which proved absolutely vital in Truck Toss) is to create a pool of objects during loading. E.g. 4 of each enemy type. When an object’s no longer needed, disable it and shove it back in the pool instead of recreating it. So you’d have a function along the lines of MakePrefab(“path/to/prefab”); which will only only call Resources.Load() provided there are none in the pool.
-Resources.Load() is even slower! This function does not cache, and involves reading from the device’s HD or equivalent. Ideally you want a hybrid pool system if you’re doing a lot of loading\unloading. I.e. your standard pool system which preloads objects,
but when the instantiate function is called, it keeps a different copy in a different list. Whenever instantiate’s called and there aren’t enough in the pool but there’s a copy in the spare list, Instantiate from that rather than doing a Resources.Load fresh again.
This is a balancing act of memory use and processor use, so target it for your device.
-GameObject.Find() and GetCompoenent().. …are slow (You saw that one coming, right?). If you’re going to be using an object or component repeatedly, then it makes sense to create a reference to it in a local variable rather than looking it up repeatedly.
-Reflective functions can be noticeably slower. Reflection is the ability for a language\code to look within itself and get method names\types\scope etc and potentially alter them. I.e. calling a function by string name, or using delegates. Try to avoid this kinda of behaviour for performance critical code.
-The garbage collector is slower yet. It has to scan trees of objects looking for orphaned classes and objects, and ‘islands’ of objects with references only to each other, determine how long they’ve been that way, and then free up the memory. Sure you can call it manually, but that’s generally more of a hint to it than a command, and shouldn’t generally be used during gameplay.
-Using too much memory……will cause IOS devices to crash\quit and your app won’t be accepted to the app store. That’s actually secondary to the point that when memory’s low, your game will slow down dramatically, especially during garbage collections and when you’re trying to instantiate new objects.
-Set your BG music to decompress on load. Anything you’ll be using a lot should probably be decompressed on load rather than streaming from the disk (which is slow and can be especially troublesome on Android.) This is another tradeoff situation however, given that decompression can take time and memory. Balance it!
-Infrequently used clips… ..may be left compressed in memory, especially if there are lots of them.
-Force to mono? Yes yes! Unless you really want stereo and you’ve got some bitchin’ music or sound effects, you’ll save yourself some space on this one. Remember the phone has a mono speaker
-Hardware decoding is faster. Well, that’s a generalisation, but faster is better.
-Unity’s UI system is slow. Where possible try to use a plugin or sprite package that renders to meshes in 3D space.
-OnGUI is slow! Even in a blank scene you can see it spike. Try to have no more than one of these in your code, and centralise branches out from it. It’s fairly easily done.
-Try to keep your UI animations in FixedTimestep() functions.This way they’ll stay consistent across multiple devices and framerates. You might benefit from having all of your game logic for every class branch out form a single base call to FixedTimeStep();
-Does your UI have to update *every* frame? You might gain a massive performance boost by deferring it to every 2nd or third frame. With truck toss, the game runs much smoother with the entirety of the game logic running on every second FixedUpdate. I know, right?
-Moar Cameras! If your game does a lot of scaling\zooming, then why have to scale the UI and risk breaking batching? Add another camera for the UI, and set UI objects’ layers to that of the camera. Again, it sounds like a lot of extra blitting, but could potentially speed your game up with very little in the way of changes.
Build Options:
-Disable the accelerometer! In older Unities, that was done via #define kaccelerometer_frequency 0 in the AppControler class via XCode. Nowadays you can disable it from within Unity itself, and can free up 2-3 FPS.
-In some cases OpenGL ES 1.0 or 2.0……will offer better performance on your device. This seems to vary between devices and Android\iOS. Try on as many devices as you can.
-Strip things down! When your game’s running nice and stable, switch compatibility to the .NET 2.0 subset, Stripping Level to micro mscorlib and Script Call Optimisation to Fast but no Exceptions. This will generate a smaller binary with less redundant code and debug symbols. I successfully navigated that one without a stripper reference. Jugs.
-Target iOS 5 where possible. There really is no discernible speed difference. However, make sure your XCode project’s settings match, or uploading to iTunes might fail. Perhaps it’s worth exporting another project.
Bonus Content – Building Faster!:
-Symlink Unity Libraries……from the build settings where possible, this will save copying more files over to xCode, by effectively creating a shortcut. Much love for symlinks.
Set your “Debug Information Format”From within Xcode (Build Settings) to STABS, otherwise have fun watching DWARF taking ages. Stabs..dwarf… Lols…
-Sometimes using “Build for “……within XCode will build and run faster. Delete the previous version on your device and give it a shot. I have no idea why this is so, but you’re welcome.
Bonus Content 2 – Faster physics modelling:
This is a fun little technique I use to convert edge chains to solid blocks!
Create a fake edge chain, where each link between 2 points is actually a stretched out, rotated cube parented to something, forming the outline of shape of your choice (cloud\star\car\whatever). Hit play, and while the game is running, drag your chain back into the editor to make a prefab. You now have a group of parented objects you can fill in and make solid. This lets you use your own code to generate physics shapes.
And finally, Break every rule. In the spirit of hacking away at things, you must fiddle and see what’s going on.If something seems like a silly idea at first, you might just not have thought about it from all angles.
Let me know if you’ve anything interesting to add. Happy hacking!
This entry was posted in , , , , , . Bookmark the .
Recentish Stuff
Categories}

我要回帖

更多关于 domove函数 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信