If anyone else is also just kind of starting out in Unity and you're having trouble finding good tutorials for the most recent version, this guy really seems to know what he's doing and his tutorials are only a few months old. He's got 5 videos in the platformer series and a few other miscellaneous tutorials as well.
Probably gonna be using that soon, when I decide to stop feature-creeping my current thing. Cheers!
As it is though, huaaarrrrghhraycasts. I've got a Line Renderer component that's drawing a pretty laser pointer, and I've got a script attached to it that's running a raycast that's returning a value for the distance to whatever it's hit, and now I'd like to put that distance into the Line Renderer so it stops drawing at the object it's colliding with.
My script (be amaaaazed) looks like this:
void Update ()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, Vector3.forward, out hit, 100.0f))
{
float distanceToTarget = hit.distance;
Debug.Log(distanceToTarget);
}
}
edit: disregard, my brother (who has a far greater understanding of programming than me) took a look at it and we eventually figured out I was making a stupid syntax error in connecting them up, and so I shall now post the finished script for future reference:
using UnityEngine;
using System.Collections;
public class LaserScript : MonoBehaviour {
private float distanceToTarget = 100f;
void Start ()
{
}
void Update ()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, Vector3.forward, out hit, 100.0f))
{
distanceToTarget = hit.distance;
Vector3 endPoint = new Vector3(0,0,distanceToTarget);
Debug.Log (endPoint);
GetComponent<LineRenderer>().SetPosition(1,endPoint);
}
}
}
I know there's probably an even neater way to do that, but it works and I'm happy with it. The biggest hold-up we had was using the '<>' in GetComponent, because the only similar example I could find was a Java one, and that used regular brackets. Once we'd realised that, it clicked into place.
I'm not entirely sure how to go about handling multiple input types. Unity's "axes" are a level of abstraction I can't quite wrap my head around. I want a player to be able to use keyboard, mouse, or gamepad to navigate menus on PC. Do I need separate GamePad and Keyboard vertical/horizontal axes? I know any axes you configure can be set up by the player to be whatever they want, but I'd prefer to provide sensible defaults. You shouldn't have to configure up/down/left/right, and you should be able to put down the gamepad and use the keyboard without configuring anything in or out of game.
I think you need two different axis if you're using a joystick for one input and buttons for another. You have to set the axis type to either, button/mouse, mouse movement, or joystick axis. So if you're using left/right on the keyboard for your horizontal axis, and you want left thumbstick to be the default for your gamepad then you'll need to make a second input that takes a joystick type input.
The biggest hold-up we had was using the '<>' in GetComponent, because the only similar example I could find was a Java one, and that used regular brackets. Once we'd realised that, it clicked into place.
I've had this problem too, once I found this page I kept it up and I check it every time I have a weird error when working from a JS tutorial, it's saved me several times:
I think you need two different axis if you're using a joystick for one input and buttons for another. You have to set the axis type to either, button/mouse, mouse movement, or joystick axis. So if you're using left/right on the keyboard for your horizontal axis, and you want left thumbstick to be the default for your gamepad then you'll need to make a second input that takes a joystick type input.
No, nothing that complex. Basically, everything is menus. The player should be able to select the active menu item with gamepad d-pad or keyboard up/down. So it sounds like I only need one axis.
@Delzhand: In that case, each axis has a primary and alternate input, you could probably just set the primary to be left/right on the keyboard, and the alt to left/right on the dpad and then set the type to button.
The biggest hold-up we had was using the '<>' in GetComponent, because the only similar example I could find was a Java one, and that used regular brackets. Once we'd realised that, it clicked into place.
I've had this problem too, once I found this page I kept it up and I check it every time I have a weird error when working from a JS tutorial, it's saved me several times:
With the upcoming release of Unity 4.3 and their new 2D pipeline, I figure it's finally time for me to settle in and learn me some Unity for a greater good.
I have an extensive programming background and I understand the basics pretty well (component-based design, fuckyeah), but there's really no good guides that I can find on how to properly architect a Unity game. Like where do you shove your main game loop, keep track of game state, transition between menus and game and such? In components? That's so weird, but that's what I keep seeing in all the tutorials.
I get the feeling that Unity suffers from PHP disease: It's so easy to work with that the quality of the popular tutorials ends up being low because they are written by people without sufficient experience.
Yeah, I'm thinking the same thing, perfect time to get into Unity. I can't find any good tutorials though.
You search for them and you get random threads from 2011 that direct you to "awesome" tutorials made for Unity 2.6. There are a bunch of them for various versions of Unity 3. But at the same time I'm not sure I trust most newer tutorials I can find, a lot of them seem very amateur. Hard to know who is giving authoritatively good advice and who is just throwing together something in a hack job to make it work.
I'm midway through the "stealth" tutorial from the unity site, that might be a good place to start. Problem is it frequently just has you do things without explaining what you're doing, but it'll certainly teach you some of the basics. I got bored at the end of chapter 3 and have been just dicking around with whatever takes my fancy since then.
Right after I posted I went looking again and found that, it does look very nice.
EDIT: According to comments though, it looks like it requires Unity Pro...?
No, I'm not using Unity Pro and its all worked so far.
In the very first video where you do anything, the one on lighting, he tells you to set the main camera to the deferred lighting rendering path, and underneath it is a big warning that says "deferred lighting requires Unity Pro." You can choose deferred lighting anyway but I'm sure it doesn't actually use it.
Later in the same video, before you bake the lights, he has you go into the lightmapping window and change the mode to directional lightmaps, which again has a warning at the bottom that says it requires a Pro license. This one doesn't let you change any settings to follow along with what he is doing, and you can't bake the texture. I switched back to dual lightmaps and I hope that works out well enough.
Oh god, just wrapping my head around Unity and just getting started... It's so hard and weird what the hell is going onnnn.
Seriously, where did you all first dip your toes? When I have a blank canvas in Unity, I have no goddamn clue what to do with it so I can even make an exploratory project.
I may actually buy a book. I don't normally do that.
With the upcoming release of Unity 4.3 and their new 2D pipeline, I figure it's finally time for me to settle in and learn me some Unity for a greater good.
I have an extensive programming background and I understand the basics pretty well (component-based design, fuckyeah), but there's really no good guides that I can find on how to properly architect a Unity game. Like where do you shove your main game loop, keep track of game state, transition between menus and game and such? In components? That's so weird, but that's what I keep seeing in all the tutorials.
I get the feeling that Unity suffers from PHP disease: It's so easy to work with that the quality of the popular tutorials ends up being low because they are written by people without sufficient experience.
Yeah, I'm thinking the same thing, perfect time to get into Unity. I can't find any good tutorials though.
You search for them and you get random threads from 2011 that direct you to "awesome" tutorials made for Unity 2.6. There are a bunch of them for various versions of Unity 3. But at the same time I'm not sure I trust most newer tutorials I can find, a lot of them seem very amateur. Hard to know who is giving authoritatively good advice and who is just throwing together something in a hack job to make it work.
I'm midway through the "stealth" tutorial from the unity site, that might be a good place to start. Problem is it frequently just has you do things without explaining what you're doing, but it'll certainly teach you some of the basics. I got bored at the end of chapter 3 and have been just dicking around with whatever takes my fancy since then.
Right after I posted I went looking again and found that, it does look very nice.
EDIT: According to comments though, it looks like it requires Unity Pro...?
No, I'm not using Unity Pro and its all worked so far.
In the very first video where you do anything, the one on lighting, he tells you to set the main camera to the deferred lighting rendering path, and underneath it is a big warning that says "deferred lighting requires Unity Pro." You can choose deferred lighting anyway but I'm sure it doesn't actually use it.
Later in the same video, before you bake the lights, he has you go into the lightmapping window and change the mode to directional lightmaps, which again has a warning at the bottom that says it requires a Pro license. This one doesn't let you change any settings to follow along with what he is doing, and you can't bake the texture. I switched back to dual lightmaps and I hope that works out well enough.
Hmm, yeah, forgot about that. In any case it only affects the way it looks, you can just skip that step and it still works just fine.
Well after far too long I finally have a working diving helmet model that I've attached to the camera such that you can look around and the helmet follows behind your viewpoint on a delay, ala "Blue Marble". One remaining problem that I'm not sure how to solve is that if you quickly turn more than 180 degrees, to the left say, the helmet takes the path of least resistance and turns right instead. This is eventually planned to be an Oculus Rift application so in theory people won't be able to turn their heads as quickly as I can flick the mouse around, so it might not be an issue.
Next step is going to be playing with the FPS controller to enable underwatery-style movement, which might be a pain given its all written in javascript and I've been doing all my coding in C#. A bigger challenge is going to be getting water, particularly the surface itself, to look and feel right. It seems like this isn't an easy thing to do in Unity, given that there are $500 water physics packages out there. For now, I'll probably just slap a blue filter over the camera when your height drops below "sea-level".
I'm doing the stealth game tutorial, just finished chapter 2-4, player movement. Got to the point where you're supposed to test your player out and walk around a bit...except my player walks on his own, in little short bursts, walking, sneaking, stopping, mostly forward and a little to the left.
I pored over the movement script to see if I messed anything up and I couldn't find anything, so I gave up and copied the tutorial's code and pasted it in and rebuilt...and he's still doing it. I've searched online and can't find any help.
So what the hell do I do? I guess it's hosed. I have no idea where this went wrong. Probably some set of properties buried deep in the inspector somewhere. I don't want to spend an hour trying to rebuild everything, but I do want to finish this...
I'm doing the stealth game tutorial, just finished chapter 2-4, player movement. Got to the point where you're supposed to test your player out and walk around a bit...except my player walks on his own, in little short bursts, walking, sneaking, stopping, mostly forward and a little to the left.
I pored over the movement script to see if I messed anything up and I couldn't find anything, so I gave up and copied the tutorial's code and pasted it in and rebuilt...and he's still doing it. I've searched online and can't find any help.
So what the hell do I do? I guess it's hosed. I have no idea where this went wrong. Probably some set of properties buried deep in the inspector somewhere. I don't want to spend an hour trying to rebuild everything, but I do want to finish this...
I remember having an issue with that one, can't remember what I did to fix it though; I'll see if I can remember when I get home and can actually look at the code. It was something pretty simple, I think. I just flipped a switch somewhere and suddenly it worked.
I'm doing the stealth game tutorial, just finished chapter 2-4, player movement. Got to the point where you're supposed to test your player out and walk around a bit...except my player walks on his own, in little short bursts, walking, sneaking, stopping, mostly forward and a little to the left.
I pored over the movement script to see if I messed anything up and I couldn't find anything, so I gave up and copied the tutorial's code and pasted it in and rebuilt...and he's still doing it. I've searched online and can't find any help.
So what the hell do I do? I guess it's hosed. I have no idea where this went wrong. Probably some set of properties buried deep in the inspector somewhere. I don't want to spend an hour trying to rebuild everything, but I do want to finish this...
That kind of behavior sounds like it's due to either input processing (maybe not enough deadzone on joystick/gamepad input, or requires calibration?) or some kind of physics issue. I'd see what happens if all affects of user input on the guy are disabled, and maybe try replacing the collision component.
Thanks for the ideas, I'll see if I can play with it tomorrow.
I know it's just a tutorial and not like something real that I need to get working, but I want to do this right. I feel like it's been valuable so far, I've picked up quite a bit from it and I'd like to know what's wrong so I know how to fix it if it happens again.
Some other info: I have no additional controllers hooked up, just keyboard and mouse. I can control the character normally as long as I keep pressing the arrow keys, but when I let go he moves on his own. It looks like he is cycling through a couple animations, walk, sneak, idle in less than a second. Holding left shift is supposed to make the character go into sneak mode, but instead it halts all movement, if I hold shift and arrow keys he just rotates in place. Tapping shift several times seems to make the character toggle between always sneaking and always running. Z works for yelling "hey" like it is supposed to.
The control weirdness really makes me think it's something in code, but I directly copied their code from the page (C#) and it still does it.
Oh god, just wrapping my head around Unity and just getting started... It's so hard and weird what the hell is going onnnn.
Seriously, where did you all first dip your toes? When I have a blank canvas in Unity, I have no goddamn clue what to do with it so I can even make an exploratory project.
I may actually buy a book. I don't normally do that.
You could try going the way I'm currently working, which is to work through this tutorial here: http://www.3dbuzz.com/training/view/unity-standard/simple-2d-shooter
then start feature-creeping the game. I started by turning it from a 2d shooter into 3d (was surprisingly easy to do), then changing the way the asteroids spawn to allow multiple instances, implementing a way to let the player change weapons, then weapon overheating and cooldown, a laser pointer thing to show where you're aiming, and anything else I can think of to get my hands dirty and see what I can do. I've got more ideas for further stuff, but I'm now getting to a point where I feel I could start planning what to do next.
edit: I'm probably the least qualified person here to take a shot at your problem, Sporky, but from the way you describe it and some of the problems I've come across, it kind of sounds like there's a boolean that's being flipped on and off in a loop somewhere, which I'd have to guess was in the MovementManagement section. Captain Helpful awaaaaaaaaaaaaaay.
the problem is if I have a skybox the objects using that shader totally disappear. If the background of the object is another quad they work fine. I searched a bit and I know its something in the shader code but I dont know enough to know what and would really like to find the answer without having to become a shader programmer, though I probably will have to eventually.
So the question is, does anyone know enough about shaders to know why the skybox would be making objects with materials using this shader not be drawn?
I'm trying to figure out how to spawn two this afterburner particle thing I've knocked up, and fix them to the back of the ship as it flies off into space. I know how to instantiate a prefab at a specific location, but right now instead of spawning a single instance (I'm getting one working, then I'll do the other) which is affixed to the ship, it's farting a brightly-coloured trail across the sky as it goes. Looks pretty, but not what I was aiming for.
I got the shader working, had to add this line: Tags {"Queue" = "Transparent" } just after the SubShader routine to force the result to be drawn AFTER the skybox. I still have no idea what I'm doing but my futile poking is working!
That kind of behavior sounds like it's due to either input processing (maybe not enough deadzone on joystick/gamepad input, or requires calibration?) or some kind of physics issue. I'd see what happens if all affects of user input on the guy are disabled, and maybe try replacing the collision component.
Aw snap it was the PlayerAnimator.
The components come with a Done folder that has finished versions of every aspect of the project, and I dragged in DonePlayerAnimator instead of the one it had me create. Works fine with that.
Maybe I pressed some button by accident that was a hotkey for something or other, who knows.
Mecanim really blows my mind, I can't believe that kind of tool is free with Unity. It seems complicated but also potentially intuitive, once you know what you're doing. Just awesome.
You could try going the way I'm currently working, which is to work through this tutorial here: http://www.3dbuzz.com/training/view/unity-standard/simple-2d-shooter
then start feature-creeping the game. I started by turning it from a 2d shooter into 3d (was surprisingly easy to do), then changing the way the asteroids spawn to allow multiple instances, implementing a way to let the player change weapons, then weapon overheating and cooldown, a laser pointer thing to show where you're aiming, and anything else I can think of to get my hands dirty and see what I can do. I've got more ideas for further stuff, but I'm now getting to a point where I feel I could start planning what to do next.
I love doing that, it's always the easiest way for me to learn programming.
In my high school (and the rest of the world) everyone had either a TI-83 or TI-86...I was one of the few people with a TI-85. A lot fewer games were made for it. I wanted to play Mario, but all I could find was a Mario-esque game some guy had ported from the computer called Sqrxz. I learned assembly by hacking that thing into some semblance of Mario, modifying his enemies (turning one into a moving platform), etc.
Alright, this should be a relatively simple problem, but I can't for the life of me figure it out; how do I refer to classes or variables I've declared in another file?
Here's the problem. I have a FPS controller, which has my main camera attached to it as a child. I have my main camera running a script called "underwaterTransition" which puts a fog and blue filter over the camera when the camera's y-axis goes below a certain value. This all works fine and I'd like to keep it. I also have an "IsUnderwater" bool set on my FPS controller so that I can switch between the default FPS movement and "free" movement where you can travel in whatever direction you like to simulate swimming. Manually switching the bool works fine, but I need it to be automatic.
The FPS controller's main script has "TheCamera" declared publicly, and i've put the main camera in there. In this way, it knows which way the camera is facing, and can handle movement based on that. But, the only properties of the camera I can access are the basic ones that exist on any other game object. What I need is to be able to access the "IsUnderwater" bool from the camera, so that I can set "IsUnderwater" on the FPS controller to be the same thing. Otherwise I'm going to end up duplicating code, which is not ideal.
Is this something I can do, or am I approaching the problem wrong?
@darleysam: It might sounds simple but, make sure you're not instantiating it in the Update function. It sounds like you're instantiating a new emitter every time you want to emit, try enabling/disabling it instead.
Alright, this should be a relatively simple problem, but I can't for the life of me figure it out; how do I refer to classes or variables I've declared in another file?
Here's the problem. I have a FPS controller, which has my main camera attached to it as a child. I have my main camera running a script called "underwaterTransition" which puts a fog and blue filter over the camera when the camera's y-axis goes below a certain value. This all works fine and I'd like to keep it. I also have an "IsUnderwater" bool set on my FPS controller so that I can switch between the default FPS movement and "free" movement where you can travel in whatever direction you like to simulate swimming. Manually switching the bool works fine, but I need it to be automatic.
The FPS controller's main script has "TheCamera" declared publicly, and i've put the main camera in there. In this way, it knows which way the camera is facing, and can handle movement based on that. But, the only properties of the camera I can access are the basic ones that exist on any other game object. What I need is to be able to access the "IsUnderwater" bool from the camera, so that I can set "IsUnderwater" on the FPS controller to be the same thing. Otherwise I'm going to end up duplicating code, which is not ideal.
Is this something I can do, or am I approaching the problem wrong?
You need to make IsUnderwater publically accessible somehow. The simplest way to do that is to use the "public" keyword when declaring it, but that's considered "unsafe". Another way to do it would be to make a public method in your camera class which returns the value of IsUnderwater, which would let you do what you want without letting other classes change it directly.
Right, but that's just the problem; I don't know how to add code to the "camera class". As far as I can see, adding scripts to the camera in the inspector adds them as their own objects under the camera itself; I don't know how to access anything I put in there from the outside. Like I can access the camera's position or its rotation because they're part of the object itself, but how do I use variables/functions from scripts attached to the object?
What you're looking for is "GetComponent". So if you have a reference to the camera object, you can access the UnderwaterTransition* component like this:
public class MyClass : MonoBehaviour {
public Camera myCamera; //you can set this in Inspector or find it manually in code -- we will assume the former
UnderwaterTransition transitionFilter;
void Start () {
transitionFilter = myCamera.GetComponent( typeof( UnderwaterTransition ) ) as UnderwaterTransition;
if ( transitionFilter ) {
transitionFilter.DoThings();
}
}
}
A few notes:
- You should also be able to just specify "public UnderwaterTransition transitionFilter" and assign it via Inspector, by dropping the same Camera object into that slot as well. Any public variable that asks for an instance of a script that extends MonoBehaviour will accept any GameObject that has that script as a component.
- The "GetComponent( typeOf( Type ) ) as Type" format returns "null" if the component isn't found, which makes it easy to verify your search was successful before proceeding.
* Standard convention is for classes and functions to capitalize the first letter of every word, while variables only capitalize each word after the first.
What you're looking for is "GetComponent". So if you have a reference to the camera object, you can access the UnderwaterTransition* component like this:
public class MyClass : MonoBehaviour {
public Camera myCamera; //you can set this in Inspector or find it manually in code -- we will assume the former
UnderwaterTransition transitionFilter;
void Start () {
transitionFilter = myCamera.GetComponent( typeof( UnderwaterTransition ) ) as UnderwaterTransition;
if ( transitionFilter ) {
transitionFilter.DoThings();
}
}
}
A few notes:
- You should also be able to just specify "public UnderwaterTransition transitionFilter" and assign it via Inspector, by dropping the same Camera object into that slot as well. Any public variable that asks for an instance of a script that extends MonoBehaviour will accept any GameObject that has that script as a component.
- The "GetComponent( typeOf( Type ) ) as Type" format returns "null" if the component isn't found, which makes it easy to verify your search was successful before proceeding.
* Standard convention is for classes and functions to capitalize the first letter of every word, while variables only capitalize each word after the first.
Doesn't work, at least not for me. I see examples of people just using classes they've declared in other scripts like its nothing, so it seems like it should just work, and yet for me it simply refuses to. I can't declare an object of type UnderwaterTransition from outside of the script file itself. The script refuses to compile because "The name 'UnderwaterTransition' does not denote a valid type ('not found'). "
What gives?
*edit* I should add that I'm trying to reference a class declared in C# from javascript, that's probably pretty important. Googling suggests this is possible, but again, not working for me. It does appear that I can reference the UnderwaterTransition class from another C# script.
Also, something that's been bothering me since I started learning Unity... when you write something like "if (transform.position.y < underwaterLevel)", does the script just assume that "transform" is the transform of the object the script is attached to? Likewise if I put "camera.backgroundColor = new Color(0, 0.4f, 0.7f, 1);" does Unity know that "camera" refers to the object the script is attached to and behave appropriately? What if the object isn't actually a camera? I ask because I tried taking out the inheritance to "MonoBehavior" that all the scripts seem to start with, just to see what would happen, and those lines immediately stopped working. Is this what the MonoBehavior class is for?
*edit* Alright, solved my first problem, would still appreciate some insight into the second.
C# and javascript can't see each other at compile time because the compilers are different - but scripts already compiled can be accessed, no matter in which language they were written. To help solving this problem, Unity compiles scripts in 3 consecutive waves: scripts in Standard Assets, Pro Standard Assets and Plugins are compiled first, scripts in the Editor subfolders of these folders are compiled next, and scripts in other folders are compiled last (see Script Compilation in the docs). You could place the C# script in Plugins or Standard Assets, and the other scripts in another folder - Assets/Scripts, for instance.
So I moved the FPS controller scripts out of the standard assets folder, and put the UnderwaterTransition into it, and bam, working. This is annoying, because its something I absolutely would not have figured out on my own. It has convinced me however that at some point I need to re-write the entire FPS controller in C#, as the standard one only comes in javascript.
*edit* Alright, another issue, last one because I think I'm going to call it a day now. My terrain isn't always colliding properly. I have a mountain I generated with a heightmap, and my FPS controller doesn't seem to be colliding with the sides of the mountain, particularly where it gets steep. If the ground is flat, everything works fine. If I hit a slope, there's a good chance I'll end up falling through the terrain. I added a debug message that triggers every time a collision is detected by OnControllerColliderHit, and the collisions aren't even being picked up in most cases. What's going on here?
@darleysam: It might sounds simple but, make sure you're not instantiating it in the Update function. It sounds like you're instantiating a new emitter every time you want to emit, try enabling/disabling it instead.
Yeah, this seems like it'll be the best way for me to do it. I've wrapped everything up into a single prefab that's a child of the Player's ship, disabled it, and now I just need to figure out the correct syntax for activating it. I had a quick go with Transform.Find this morning, but couldn't get it to work.
Let's say I generate a level out of blocks. Whole bunch of individual instantiated cubes, all identical.
Is there a simple way to merge and optimize their meshes, something like this:
Bonus points if I can also automatically tile and offset the texture so that it still looks like a bunch of individual blocks.
Or do I not want to do this? Does it make things needlessly complicated? Is merging the meshes into one mesh with the same number of tris basically good enough, just to reduce the draw calls?
Let's say I generate a level out of blocks. Whole bunch of individual instantiated cubes, all identical.
Is there a simple way to merge and optimize their meshes, something like this:
Just find a Voxel engine or search how to create one. Because of the success of minecraft, there is many of them out there.
My specific intent is to make a big first person maze, and then use that same level data to generate a smaller, simpler map that I can point an ortho camera at to display a mini map in the corner. I don't have any need to optimize everything just yet, but as an experiment and just to know how to do it I'd like to try to do what I described.
Would a voxel engine be a better solution in this case?
This really won't matter once the 2D tools come out, I'll just do it that way. :P
That's more work that in needs to be. You don't need to generate another map, what you want to do is create a separate camera that points at the same map, but has a layer mask on it so it only shows the collision geometry.
Edit: I'll take a look when I get home - I guess I'm not sure if you can set up a camera to show colliders, so you'd have to have some cubes in the actual level that matched the collision geometry, and you'd exclude those from your main camera.
I don't know the first thing about making a 3D game. Can you tell?!
I'm just thinking too old school...you draw the scene over here, and then you draw a different view of the scene over here, using a different set of graphics, smaller tiles...
One of the most exciting things about it is that modifying and improving the AI is (hopefully) going to be a very clean, modular process. I'm treating the AI decision process like a bunch of filters applied to an image, where the image is a given unit's valuation of its possible actions. If I want a behavior like, "Stay distance X from friendly units," or even, "Get between friendly unit X and enemy unit Y," I just need to write a function that judges possible move valuations accordingly.
Meanwhile, these blockout visuals have gotten a bit stale so I'm going to take some time to do an art pass on the project.
I don't know the first thing about making a 3D game. Can you tell?!
I'm just thinking too old school...you draw the scene over here, and then you draw a different view of the scene over here, using a different set of graphics, smaller tiles...
well, this works for 2d as well. IIRC XNA called it a viewportRectangle, but (as you might expect), you basically had to build everything yourself, there was no build in scaling, or masking, or positioning.
0
surrealitychecklonely, but not unloveddreaming of faulty keys and latchesRegistered Userregular
One of the most exciting things about it is that modifying and improving the AI is (hopefully) going to be a very clean, modular process. I'm treating the AI decision process like a bunch of filters applied to an image, where the image is a given unit's valuation of its possible actions. If I want a behavior like, "Stay distance X from friendly units," or even, "Get between friendly unit X and enemy unit Y," I just need to write a function that judges possible move valuations accordingly.
Meanwhile, these blockout visuals have gotten a bit stale so I'm going to take some time to do an art pass on the project.
Posts
As it is though, huaaarrrrghhraycasts. I've got a Line Renderer component that's drawing a pretty laser pointer, and I've got a script attached to it that's running a raycast that's returning a value for the distance to whatever it's hit, and now I'd like to put that distance into the Line Renderer so it stops drawing at the object it's colliding with.
My script (be amaaaazed) looks like this:
void Update () { RaycastHit hit; if (Physics.Raycast(transform.position, Vector3.forward, out hit, 100.0f)) { float distanceToTarget = hit.distance; Debug.Log(distanceToTarget); } }edit: disregard, my brother (who has a far greater understanding of programming than me) took a look at it and we eventually figured out I was making a stupid syntax error in connecting them up, and so I shall now post the finished script for future reference:
using UnityEngine; using System.Collections; public class LaserScript : MonoBehaviour { private float distanceToTarget = 100f; void Start () { } void Update () { RaycastHit hit; if (Physics.Raycast(transform.position, Vector3.forward, out hit, 100.0f)) { distanceToTarget = hit.distance; Vector3 endPoint = new Vector3(0,0,distanceToTarget); Debug.Log (endPoint); GetComponent<LineRenderer>().SetPosition(1,endPoint); } } }I know there's probably an even neater way to do that, but it works and I'm happy with it. The biggest hold-up we had was using the '<>' in GetComponent, because the only similar example I could find was a Java one, and that used regular brackets. Once we'd realised that, it clicked into place.
I've had this problem too, once I found this page I kept it up and I check it every time I have a weird error when working from a JS tutorial, it's saved me several times:
http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
For example, search for GetComponent on that page and it's right there.
Actually I'm kind of shocked as to how similar the two languages are.
No, nothing that complex. Basically, everything is menus. The player should be able to select the active menu item with gamepad d-pad or keyboard up/down. So it sounds like I only need one axis.
Bookmarking thiiiiis, thank you.
In the very first video where you do anything, the one on lighting, he tells you to set the main camera to the deferred lighting rendering path, and underneath it is a big warning that says "deferred lighting requires Unity Pro." You can choose deferred lighting anyway but I'm sure it doesn't actually use it.
Later in the same video, before you bake the lights, he has you go into the lightmapping window and change the mode to directional lightmaps, which again has a warning at the bottom that says it requires a Pro license. This one doesn't let you change any settings to follow along with what he is doing, and you can't bake the texture. I switched back to dual lightmaps and I hope that works out well enough.
if ( GlobalVars.debug_ISeeWhatYouDidThere ) {Seriously, where did you all first dip your toes? When I have a blank canvas in Unity, I have no goddamn clue what to do with it so I can even make an exploratory project.
I may actually buy a book. I don't normally do that.
Hmm, yeah, forgot about that. In any case it only affects the way it looks, you can just skip that step and it still works just fine.
Well after far too long I finally have a working diving helmet model that I've attached to the camera such that you can look around and the helmet follows behind your viewpoint on a delay, ala "Blue Marble". One remaining problem that I'm not sure how to solve is that if you quickly turn more than 180 degrees, to the left say, the helmet takes the path of least resistance and turns right instead. This is eventually planned to be an Oculus Rift application so in theory people won't be able to turn their heads as quickly as I can flick the mouse around, so it might not be an issue.
Next step is going to be playing with the FPS controller to enable underwatery-style movement, which might be a pain given its all written in javascript and I've been doing all my coding in C#. A bigger challenge is going to be getting water, particularly the surface itself, to look and feel right. It seems like this isn't an easy thing to do in Unity, given that there are $500 water physics packages out there. For now, I'll probably just slap a blue filter over the camera when your height drops below "sea-level".
I'm doing the stealth game tutorial, just finished chapter 2-4, player movement. Got to the point where you're supposed to test your player out and walk around a bit...except my player walks on his own, in little short bursts, walking, sneaking, stopping, mostly forward and a little to the left.
I pored over the movement script to see if I messed anything up and I couldn't find anything, so I gave up and copied the tutorial's code and pasted it in and rebuilt...and he's still doing it. I've searched online and can't find any help.
So what the hell do I do? I guess it's hosed. I have no idea where this went wrong. Probably some set of properties buried deep in the inspector somewhere. I don't want to spend an hour trying to rebuild everything, but I do want to finish this...
I remember having an issue with that one, can't remember what I did to fix it though; I'll see if I can remember when I get home and can actually look at the code. It was something pretty simple, I think. I just flipped a switch somewhere and suddenly it worked.
That kind of behavior sounds like it's due to either input processing (maybe not enough deadzone on joystick/gamepad input, or requires calibration?) or some kind of physics issue. I'd see what happens if all affects of user input on the guy are disabled, and maybe try replacing the collision component.
I know it's just a tutorial and not like something real that I need to get working, but I want to do this right. I feel like it's been valuable so far, I've picked up quite a bit from it and I'd like to know what's wrong so I know how to fix it if it happens again.
Some other info: I have no additional controllers hooked up, just keyboard and mouse. I can control the character normally as long as I keep pressing the arrow keys, but when I let go he moves on his own. It looks like he is cycling through a couple animations, walk, sneak, idle in less than a second. Holding left shift is supposed to make the character go into sneak mode, but instead it halts all movement, if I hold shift and arrow keys he just rotates in place. Tapping shift several times seems to make the character toggle between always sneaking and always running. Z works for yelling "hey" like it is supposed to.
The control weirdness really makes me think it's something in code, but I directly copied their code from the page (C#) and it still does it.
In case you need to see what the game is supposed to be like, here's Unity's final version in the web player.
You could try going the way I'm currently working, which is to work through this tutorial here: http://www.3dbuzz.com/training/view/unity-standard/simple-2d-shooter
then start feature-creeping the game. I started by turning it from a 2d shooter into 3d (was surprisingly easy to do), then changing the way the asteroids spawn to allow multiple instances, implementing a way to let the player change weapons, then weapon overheating and cooldown, a laser pointer thing to show where you're aiming, and anything else I can think of to get my hands dirty and see what I can do. I've got more ideas for further stuff, but I'm now getting to a point where I feel I could start planning what to do next.
edit: I'm probably the least qualified person here to take a shot at your problem, Sporky, but from the way you describe it and some of the problems I've come across, it kind of sounds like there's a boolean that's being flipped on and off in a loop somewhere, which I'd have to guess was in the MovementManagement section. Captain Helpful awaaaaaaaaaaaaaay.
I'm trying to get this shader working http://wiki.unity3d.com/index.php/BarycentricWireframeUv1 for a cool effect where if any bricks are between the puck and the camera they become transparent
the problem is if I have a skybox the objects using that shader totally disappear. If the background of the object is another quad they work fine. I searched a bit and I know its something in the shader code but I dont know enough to know what and would really like to find the answer without having to become a shader programmer, though I probably will have to eventually.
So the question is, does anyone know enough about shaders to know why the skybox would be making objects with materials using this shader not be drawn?
Aw snap it was the PlayerAnimator.
The components come with a Done folder that has finished versions of every aspect of the project, and I dragged in DonePlayerAnimator instead of the one it had me create. Works fine with that.
Maybe I pressed some button by accident that was a hotkey for something or other, who knows.
Mecanim really blows my mind, I can't believe that kind of tool is free with Unity. It seems complicated but also potentially intuitive, once you know what you're doing. Just awesome.
I love doing that, it's always the easiest way for me to learn programming.
In my high school (and the rest of the world) everyone had either a TI-83 or TI-86...I was one of the few people with a TI-85. A lot fewer games were made for it. I wanted to play Mario, but all I could find was a Mario-esque game some guy had ported from the computer called Sqrxz. I learned assembly by hacking that thing into some semblance of Mario, modifying his enemies (turning one into a moving platform), etc.
Steam Support is the worst. Seriously, the worst
Here's the problem. I have a FPS controller, which has my main camera attached to it as a child. I have my main camera running a script called "underwaterTransition" which puts a fog and blue filter over the camera when the camera's y-axis goes below a certain value. This all works fine and I'd like to keep it. I also have an "IsUnderwater" bool set on my FPS controller so that I can switch between the default FPS movement and "free" movement where you can travel in whatever direction you like to simulate swimming. Manually switching the bool works fine, but I need it to be automatic.
The FPS controller's main script has "TheCamera" declared publicly, and i've put the main camera in there. In this way, it knows which way the camera is facing, and can handle movement based on that. But, the only properties of the camera I can access are the basic ones that exist on any other game object. What I need is to be able to access the "IsUnderwater" bool from the camera, so that I can set "IsUnderwater" on the FPS controller to be the same thing. Otherwise I'm going to end up duplicating code, which is not ideal.
Is this something I can do, or am I approaching the problem wrong?
the bricks between the camera and the puck turn transparent making a window you can see through to aim
public class MyClass : MonoBehaviour { public Camera myCamera; //you can set this in Inspector or find it manually in code -- we will assume the former UnderwaterTransition transitionFilter; void Start () { transitionFilter = myCamera.GetComponent( typeof( UnderwaterTransition ) ) as UnderwaterTransition; if ( transitionFilter ) { transitionFilter.DoThings(); } } }A few notes:
- You should also be able to just specify "public UnderwaterTransition transitionFilter" and assign it via Inspector, by dropping the same Camera object into that slot as well. Any public variable that asks for an instance of a script that extends MonoBehaviour will accept any GameObject that has that script as a component.
- The "GetComponent( typeOf( Type ) ) as Type" format returns "null" if the component isn't found, which makes it easy to verify your search was successful before proceeding.
* Standard convention is for classes and functions to capitalize the first letter of every word, while variables only capitalize each word after the first.
Doesn't work, at least not for me. I see examples of people just using classes they've declared in other scripts like its nothing, so it seems like it should just work, and yet for me it simply refuses to. I can't declare an object of type UnderwaterTransition from outside of the script file itself. The script refuses to compile because "The name 'UnderwaterTransition' does not denote a valid type ('not found'). "
What gives?
*edit* I should add that I'm trying to reference a class declared in C# from javascript, that's probably pretty important. Googling suggests this is possible, but again, not working for me. It does appear that I can reference the UnderwaterTransition class from another C# script.
Also, something that's been bothering me since I started learning Unity... when you write something like "if (transform.position.y < underwaterLevel)", does the script just assume that "transform" is the transform of the object the script is attached to? Likewise if I put "camera.backgroundColor = new Color(0, 0.4f, 0.7f, 1);" does Unity know that "camera" refers to the object the script is attached to and behave appropriately? What if the object isn't actually a camera? I ask because I tried taking out the inheritance to "MonoBehavior" that all the scripts seem to start with, just to see what would happen, and those lines immediately stopped working. Is this what the MonoBehavior class is for?
*edit* Alright, solved my first problem, would still appreciate some insight into the second.
So I moved the FPS controller scripts out of the standard assets folder, and put the UnderwaterTransition into it, and bam, working. This is annoying, because its something I absolutely would not have figured out on my own. It has convinced me however that at some point I need to re-write the entire FPS controller in C#, as the standard one only comes in javascript.
*edit* Alright, another issue, last one because I think I'm going to call it a day now. My terrain isn't always colliding properly. I have a mountain I generated with a heightmap, and my FPS controller doesn't seem to be colliding with the sides of the mountain, particularly where it gets steep. If the ground is flat, everything works fine. If I hit a slope, there's a good chance I'll end up falling through the terrain. I added a debug message that triggers every time a collision is detected by OnControllerColliderHit, and the collisions aren't even being picked up in most cases. What's going on here?
Yeah, this seems like it'll be the best way for me to do it. I've wrapped everything up into a single prefab that's a child of the Player's ship, disabled it, and now I just need to figure out the correct syntax for activating it. I had a quick go with Transform.Find this morning, but couldn't get it to work.
Is there a simple way to merge and optimize their meshes, something like this:
Bonus points if I can also automatically tile and offset the texture so that it still looks like a bunch of individual blocks.
Or do I not want to do this? Does it make things needlessly complicated? Is merging the meshes into one mesh with the same number of tris basically good enough, just to reduce the draw calls?
it is surprisingly hard
godbless
There's your problem, bro. Set your Turgidity to about 0.1 and try disabling Arousal.
Just find a Voxel engine or search how to create one. Because of the success of minecraft, there is many of them out there.
My specific intent is to make a big first person maze, and then use that same level data to generate a smaller, simpler map that I can point an ortho camera at to display a mini map in the corner. I don't have any need to optimize everything just yet, but as an experiment and just to know how to do it I'd like to try to do what I described.
Would a voxel engine be a better solution in this case?
This really won't matter once the 2D tools come out, I'll just do it that way. :P
Edit: I'll take a look when I get home - I guess I'm not sure if you can set up a camera to show colliders, so you'd have to have some cubes in the actual level that matched the collision geometry, and you'd exclude those from your main camera.
I don't know the first thing about making a 3D game. Can you tell?!
I'm just thinking too old school...you draw the scene over here, and then you draw a different view of the scene over here, using a different set of graphics, smaller tiles...
I've added basic AI to my project!
One of the most exciting things about it is that modifying and improving the AI is (hopefully) going to be a very clean, modular process. I'm treating the AI decision process like a bunch of filters applied to an image, where the image is a given unit's valuation of its possible actions. If I want a behavior like, "Stay distance X from friendly units," or even, "Get between friendly unit X and enemy unit Y," I just need to write a function that judges possible move valuations accordingly.
Meanwhile, these blockout visuals have gotten a bit stale so I'm going to take some time to do an art pass on the project.
well, this works for 2d as well. IIRC XNA called it a viewportRectangle, but (as you might expect), you basically had to build everything yourself, there was no build in scaling, or masking, or positioning.
that is fkin pimpin looking dog
r u using the unity pro ai system?
also did u make all dem modelz?