近期热门
粉丝2
关注 0
获赞 1
Unity3D Ball and Chain – Part 1,球与链条

[U3D] Unity3D Ball and Chain – Part 1,球与链条

[复制链接]
4599 4 0 0 12年前 举报
老外蛮有一意思的一个练习,可以调整旋转速度,及轴的高低,并可将链条上的球高速抛出。具体效果在教程最后。
Making the transition from Flash and ActionScript to Unity and its JavaScript/C# has been very smooth, thanks to their detailed scripting reference and very active forums. Being one of those people when faced with flat-pack to assemble, grabs a hammer and gets stuck-in, there have been plenty of sticking points which have had me reaching for the instructions.
This is a tech demo of Unity that was created over the weekend to overcome some of the challenges that might arise when working on commercial Unity work. Initially it was created as a one off, but after finding and solving quite a few problems, I thought it might be nice to share my solutions to some of these problems as I develop the project in my spare time.
Controls: Up & Down (or W & S) to raise or lower the spinner, scroller adjusts spinning speed, and Space Bar to release the ball.
Moving skyboxes = multiple cameras.
One of the fastest things to set up is a simple skybox. It creates a visually pleasing backdrop and can add a lot to a game. After looking at a static skybox for a long time, it can get a bit “samey”. A quick look on the official forums and people were suggesting using multiple camera and setting up combinations of Clear Flags and Culling Masks. That’s all pretty easy to sort out, add another camera, I chose to make it a child of my main camera, and set its Clear Flags to “Skybox” and Culling mask to “Nothing”. Setting the main camera Clear Flags to “DepthOnly” and its Culling Mask to “Everything” gave me the correct result in each camera, just the skybox through the child and everything else with a blank area for the Skybox to sit. The problem was the child rendering the skybox on top of everything, the solution?skyCamera.camera.depth = 1;mainCamera.camera.depth = 2;


Setting the camera depth property programmatically solved the issue. So now the skybox is rendered through a different camera, it’s free to rotate slowly and give you a dynamic backdrop.
Scripted Joints.
An annoying problem with a very simple solution! I wanted the chain to be made out of a varying number of links, so I could create short and long ones out of the same code. Another self-imposed requirement was making something useable out of the physics components. So, dynamic joints and rigidbodies were the order of the day. After messing about with the properties of configurable joints, I couldn’t understand why none of them had any discernable affect on my rigidbodies. One of those classic palm-to-forehead moments ensued when I realised you need to set the connected rigidbody AFTER setting all the variables!//Set all variables, then:cJoint.connectedBody = myChild.transform.rigidbody;


These were two of the “little things” that caused me frustration, if my solutions solved either of the problems for you, I hope you found this post sooner rather than later!
Check back for more problem based solutions as I develop the project further. If there’s any interest, I’ll post the project source code after each project step. Enjoy!
0
点赞
0
打赏
0
添加到收藏夹

0

点击复制链接

使用微信扫码分享
一次扣10个券
全部评论3
您需要登录后才可以回帖 登录




dvsdbdb
7年前
回复

使用道具 举报

不错
9年前
回复

使用道具 举报

{:7_239:}怎么有时候显示的是乱码哦{:7_239:}
10年前
回复

使用道具 举报

您当前使用的浏览器IE内核版本过低会导致网站显示错误

请使用高速内核浏览器或其他浏览器