[QUOTE=Richy19;44147534]Im trying to draw a grid over a plain using
(code)
attached to the camera, but its not drawn (or is drawn behind the plane) when drawing the plane, and is just a small line when I disable the plane's renderer[/QUOTE]
See how this goes for you.
[csharp]
using UnityEngine;
using System.Collections;
public class grid : MonoBehaviour {
public float GridSpacing = 1;
public Color GridColor = Color.yellow;
public Transform plane;
private Vector3 gridSize;
private Material lineMaterial;
// Use this for initialization
void Start () {
gridSize = plane.localScale;
lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " +
" BindChannels {" +
" Bind \"vertex\", vertex Bind \"color\", color }" +
"} } }" );
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
// Update is called once per frame
void OnPostRender () {
lineMaterial.SetPass(0);
GL.Begin( GL.LINES );
GL.Color(GridColor);
float halfX = gridSize.x * 5;
float halfY = gridSize.z * 5;
for (float x = - halfX; x <= halfX; x+=GridSpacing) {
GL.Vertex3 (x, plane.localPosition.y + 0.05f, halfY);
GL.Vertex3 (x, plane.localPosition.y + 0.05f, -halfY);
}
for (float y = - halfY; y <= halfY; y+=GridSpacing) {
GL.Vertex3 (-halfX, plane.localPosition.y + 0.05f, y);
GL.Vertex3 (halfX, plane.localPosition.y + 0.05f, y);
}
GL.End();
}
}
[/csharp]
Some Changes:
- Added the plane as a Public Transform (so make sure you assign it), just makes it easier.
- OnPostDraw wasn't working for me for some reason, changed to OnPostRender
- Most of your ints work better as floats
- Had to increase the size of the scale of the grid, not half it. Don't ask me why x5 works, it just does for some reason.
- Added a value to the y in Gl.Vertex3 so the grid is visible, should also work with 0.01f
- GridSize works better as a Vector3, so I changed HalfY to be a Z value
I didn't change the names of HalfX and HalfY cause lazy.
[editline]7th March 2014[/editline]
Also, be careful with the grid size on that. The smaller grid size you go the lower your FPS will drop.
I'm sure there's either cleaner version of that code or there is a better option for drawing a grid.
Correction: Lower grid spacing seems to be fine with that code. Is was using the transform.localscale.y as the z on the vector3 that was causing that.
So figured it out thanks to the above, firstly
Vector2 gridSize;
Was only picking the transform of x and y, not z
Second, I assumed the plane was 1*1 therefore gridsize was only the scale size, but the plane is actually 10x10 so I needed to times the scale by 10 to get it correct
Is there any way to automatically generate a 2D collision mesh based off a spirte? If not, is it possible to turn a mesh collider inside out? Basically I want to know if my parts' colliders are inside of the hull's outline, as shown in the pic attached. I wouldn't mind if I needed to create a separate image with only black for the collider and transparent or white for not the collider.
[t]http://i.imgur.com/ROqRZQ0.png[/t]
So for example all the guns would get a gun-shaped hitbox and the hull would get an inside-out hull shaped hitbox, so I could know if the guns are poking out of the hull at all.
Or in other words, I need to know if it's possible to tell when black lines are touching black lines of a different part.
[quote][img]http://facepunch.com/image.php?u=498115&dateline=1382403206[/img][/quote]
TIL.
[QUOTE=Trekintosh;44157362]Is there any way to automatically generate a 2D collision mesh based off a spirte? If not, is it possible to turn a mesh collider inside out? Basically I want to know if my parts' colliders are inside of the hull's outline, as shown in the pic attached. I wouldn't mind if I needed to create a separate image with only black for the collider and transparent or white for not the collider.
[t]http://i.imgur.com/ROqRZQ0.png[/t]
So for example all the guns would get a gun-shaped hitbox and the hull would get an inside-out hull shaped hitbox, so I could know if the guns are poking out of the hull at all.
Or in other words, I need to know if it's possible to tell when black lines are touching black lines of a different part.[/QUOTE]
If you look at the sprites as point clouds, you can definitely use e.g. [URL="http://en.wikipedia.org/wiki/Convex_hull_algorithms"]convex hull algorithms[/URL] to make them, but it would be somewhat slow since you have a lot of points.
I think someone in WAYWO had an algorithm for generating vector maps from land/sea bitmaps that would work nicely here, but I don't remember who it was.
It's possible that this would be faster on the GPU, if you end up with very complicated shapes.
(The round areas are likely to generate hundreds of edges at highest resolution.)
It should be possible to set up a trigger for fast, pixel perfect collision by checking for overdraw.
[QUOTE=Tamschi;44157695]TIL.
If you look at the sprites as point clouds, you can definitely use e.g. [URL="http://en.wikipedia.org/wiki/Convex_hull_algorithms"]convex hull algorithms[/URL] to make them, but it would be somewhat slow since you have a lot of points.
I think someone in WAYWO had an algorithm for generating vector maps from land/sea bitmaps that would work nicely here, but I don't remember who it was.
It's possible that this would be faster on the GPU, if you end up with very complicated shapes.
(The round areas are likely to generate hundreds of edges at highest resolution.)
It should be possible to set up a trigger for fast, pixel perfect collision by checking for overdraw.[/QUOTE]
Well, it doesn't need to be pixel perfect at all, because the parts are on a grid, not completely freely positionable. The game is going to be played in 3D and the ships are built in 2D. The reason I want some way to automatically generate colliders based on the images is because I am designing the game from the ground up to be moddable. However, since any ship-part mod will require a 3D model, I guess it isn't out of the question to ask modders to make a collision mesh and just check if the part is inside it. However, I'd much rather use the images. Here, let me get a video of the game i'm drawing inspiration from, so I can explain how I'm trying to make this work easier.
[editline]7th March 2014[/editline]
[media]http://www.youtube.com/watch?v=bs3GN1Bozfg[/media]
As you can see, the parts are on a grid, which I will also be using. I wonder if I can use a loop to check every possible grid space for its distance from the edge of the hull, and then forbid any part with a collision radius greater than that distance from using any grid point that would put it out of the hull. It's damn inefficient, though. I think I prefer the fast pixel perfect collision.
What's overdraw?
[QUOTE=Trekintosh;44157774][...]
As you can see, the parts are on a grid, which I will also be using. I wonder if I can use a loop to check every possible grid space for its distance from the edge of the hull, and then forbid any part with a collision radius greater than that distance from using any grid point that would put it out of the hull. It's damn inefficient, though. I think I prefer the fast pixel perfect collision.
What's overdraw?[/QUOTE]
You can precompute almost all of that, which would make it very fast.
You'd just have another bitmap that stores the possible radii.
Overdraw is when the same fragment is shaded twice on the graphics card, e.g. if you first draw the walls of a room and then the interior.
Normally you'd try to avoid it by discarding fragments as soon as it's clear they are occluded (This can happen before the fragment shader runs, if you don't compute depth there) and drawing things that are likely farther away later than others, like drawing the sky last.
I think there's a trigger for this somewhere, but if not you can also use offscreen rendering and the stencil buffer in a way that only colliding pixels are drawn, which I know is something you can query (in OpenGL).
[QUOTE=Tamschi;44157883][B]You can precompute almost all of that, which would make it very fast.
You'd just have another bitmap that stores the possible radii.[/B]
Overdraw is when the same fragment is shaded twice on the graphics card, e.g. if you first draw the walls of a room and then the interior.
Normally you'd try to avoid it by discarding fragments as soon as it's clear they are occluded (This can happen before the fragment shader runs, if you don't compute depth there) and drawing things that are likely farther away later than others, like drawing the sky last.
I think there's a trigger for this somewhere, but if not you can also use offscreen rendering and the stencil buffer in a way that only colliding pixels are drawn, which I know is something you can query (in OpenGL).[/QUOTE]
This sounds promising, however it comes back to my first question of how do I read a bitmap with Unityscript? That's really what I need to know first.
Secondly, how do I handle inter-part collisions once I figure out-of-hull collisions?
What I'd like to do is spawn tiles. A list of TileProperties is kept in the Grid class. The TileProperties spawns a TileRenderer, and the TileRenderer spawns the tile prefab.
Is there a way to then attach the TileProperties and TileRenderer to the newly spawned Tile prefab, or should I do this in a completely different manner?
I do this because Grid only needs TileProperties, and it seems like a more elegant solution than keeping the GameObjects in the list and having to do GetComponent every time.
[QUOTE=Trekintosh;44157985]This sounds promising, however it comes back to my first question of how do I read a bitmap with Unityscript? That's really what I need to know first.
Secondly, how do I handle inter-part collisions once I figure out-of-hull collisions?[/QUOTE]
[url]http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.ReadPixels.html[/url]
Thus begins my descent into custom collision checking.
Just kidding, this was what I was looking for and I don't know why I didn't just google "Unity read image pixels" earlier.
[editline]7th March 2014[/editline]
I am going to have to redo my parts and make some sort of scale for them. I'm thinking 1 pixel = 6 inches. That way your average battleship is about 1200 pixels wide, which is pretty good. Then all the weapons are 512x256 pixels. That way big railguns and lasers as well as guns have plenty of space.
A .PNG doesn't significantly increase in size as the dimensions go up if the vast majority of the pixels are transparent, yes?
[editline]7th March 2014[/editline]
Wait, that just lets me read the pixel of a texture. Translating this information into usable collisions is going to be difficult with my current knowledge of how Unity works. More googling it is.
[editline]7th March 2014[/editline]
Is it possible to do a raycast of what is visible, not what has a collider? So the ray will pass through transparent pixels but not solid ones? Or better yet to read a pixel? So if I tell it to raycast at certain coordinates against a certain sprite it will say "This ray sees black!" or "This ray sees white!"
[editline]7th March 2014[/editline]
HOLY SHIT! The Unity 2D Sprite Collider automatically shapes itself to fit the sprite! I've been wasting your and my time for fucking nothing goddamn! This is [B]immensely[/B] helpful!
Here's my current solution, it's ok.
[URL="http://pastebin.com/L2j9T3x8"]http://pastebin.com/0apNmAAP[/URL]
I just installed this to make some games, is there a good resource to quickly google stuff? I can't really learn from books, I prefer to learn by way of fumbling around, and just looking up stuff on a need to know basis.
[QUOTE=Nove;44161710]I just installed this to make some games, is there a good resource to quickly google stuff? I can't really learn from books, I prefer to learn by way of fumbling around, and just looking up stuff on a need to know basis.[/QUOTE]
As for the coding side of it [url]https://docs.unity3d.com/Documentation/ScriptReference/[/url]
[QUOTE=Nove;44161710]I just installed this to make some games, is there a good resource to quickly google stuff? I can't really learn from books, I prefer to learn by way of fumbling around, and just looking up stuff on a need to know basis.[/QUOTE]
There's a few great tutorials on youtube on how to make AAA games, like Assassin's Creed
So I'm pretty new to C# and VERY new to Unity. I'm trying to make a script where I can place an object on left mouse click but I can't seem to get it to work. My real trouble is coming from this if-statement. If I take it out I get my object being placed continuously until I end the session. If I use the if-statement I get "NullReferenceException: Object reference not set to an instance of an object
PlaceGameObject.Update () (at Assets/Scripts/PlaceGameObject.cs:19)" , multiple times. It's little roadblocks like these that make simple things take hours!
[code]using UnityEngine;
using System.Collections;
public class PlaceGameObject : MonoBehaviour
{
public Rigidbody GameObject;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
var mousePos = Input.mousePosition;
mousePos.z = 2.0F;
var objectPos = Camera.current.ScreenToWorldPoint (mousePos);
if (Input.GetMouseButtonDown(0))
{
Rigidbody gameObjectInstance;
gameObjectInstance = Instantiate (GameObject, objectPos, Quaternion.identity) as Rigidbody;
}
}
}
[/code]
[QUOTE=Llamaboy9;44171003]So I'm pretty new to C# and VERY new to Unity. I'm trying to make a script where I can place an object on left mouse click but I can't seem to get it to work. My real trouble is coming from this if-statement. If I take it out I get my object being placed continuously until I end the session. If I use the if-statement I get "NullReferenceException: Object reference not set to an instance of an object
PlaceGameObject.Update () (at Assets/Scripts/PlaceGameObject.cs:19)" , multiple times. It's little roadblocks like these that make simple things take hours!
[/QUOTE]
You need to take a look at the brackets in your code.
Are you absolutely sure you've assigned Rigidbody GameObject in the editor?
[editline]8th March 2014[/editline]
[QUOTE=AtomiCal;44171098]You need to take a look at the brackets in your code.[/QUOTE]
It's just a weird indenting style/formatting error by facepunch code tags, if there was a bracket too much it should throw a parsing error and not even compile.
[QUOTE=Asgard;44171101]Are you absolutely sure you've assigned Rigidbody GameObject in the editor?
[editline]8th March 2014[/editline]
It's just a weird indenting style/formatting error by facepunch code tags, if there was a bracket too much it should throw a parsing error and not even compile.[/QUOTE]
I have a prefab with a rigidbody component assigned to the Game Object parameter of my script in the inspector. I have the script as a component of Main Camera, is that ok?
Woops, didn't bother checking the line where the error occurs. You should change the Camera.current to Camera.main. Let me know if that fixes it.
[QUOTE=Asgard;44171295]Woops, didn't bother checking the line where the error occurs. You should change the Camera.current to Camera.main. Let me know if that fixes it.[/QUOTE]
I didn't even process that 19 was the line number, I've still got a lot to learn lol! Thanks, that fixed it!
I started working on a system for loading custom levels for my game.
It starts with a "Custom Level" scene which will be empty except for the SceneHandler and the CustomLevel gameobject which does the loading.
[t]https://dl.dropboxusercontent.com/u/13781308/ShareX/2014-03/2014-03-08_19-30-33.png[/t]
When the scene starts, a script on the CustomLevel gameobject will load the level file:
[code]Name = Custom Level Test
Author = Pelf
Description = Testing custom level loading
GameMode:
{
#scene
{
lightDirection: (29.4, 36.85, 12.85)
}
#player
{
position: (-1.101, 0.0, 0.5)
rotation: 320.41
initZoom: 5
initVelocity: (0.0, 0.0, 0.0)
}
#genericPlanet
{
position: (3.0, 0.0, 0.0)
rotation: (0.0, 0.0, 0.0)
scale: 3
mass: 1000
}
#genericPlanet
{
position: (-6.1, 0.0, -10.0)
rotation: (0.0, 0.0, 0.0)
scale: 1
mass: 100
}
#genericPlanet
{
position: (0.0, 0.0, 10.0)
rotation: (0.0, 0.0, 0.0)
scale: 4.56
mass: 1000
}
#torpedoSilo
{
position: (10, 0.0, 0.0)
rotation: -180
launchDelayMin: 0.5
launchDelayMax: 1.5
}
}[/code]
Then it reads through it, spawning the specified prefabs and setting their parameters. Whenever it reaches a line with a # in front, it goes through the process for getting that type of prefabs parameters and spawning/setting it.
The result:
[t]https://dl.dropboxusercontent.com/u/13781308/ShareX/2014-03/2014-03-08_19-30-43.png[/t]
So I'm making a top down shooter kinda thing, and want to rotate my player model to face the mouse. This was my attempt, but it's just rotating the player object so that it's flat.
[code] ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray,out hit,100)){
Debug.Log("yay" + hit.point.x.ToString());
}
rigidbody.MoveRotation(Quaternion.Euler(new Vector3(0,Vector3.Angle(rigidbody.position, hit.point),0)));[/code]
Is this the right way to go about doing it?
[QUOTE=chaz13;44194581]So I'm making a top down shooter kinda thing, and want to rotate my player model to face the mouse. This was my attempt, but it's just rotating the player object so that it's flat.
Is this the right way to go about doing it?[/QUOTE]
I've always done it as something along these lines but not 100% sure if it'll work in your case.
[csharp]
Plane playerPlane = new Plane(Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float hitDist = 0.0f;
if(playerPlane.Raycast(ray, out hitDist))
{
Vector3 targetPoint = ray.GetPoint(hitDist);
Quaternion targetRotation = Quaternion.LookRotation(targetPoint - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotateSpeed);
}
[/csharp]
Where rotatespeed is a float you can set. Basically you raycast to an intersecting plane to determine where your mouse is in 3D space for your character to look at.
Was wondering, where do you guys get assets from? Assuming you don't make them yourselves, and you don't buy them. Is there any good free Unity asset websites I should know about? Mainly looking for things like dungeon walls and shit like that.
[QUOTE=Over-Run;44196562]Was wondering, where do you guys get assets from? Assuming you don't make them yourselves, and you don't buy them. Is there any good free Unity asset websites I should know about? Mainly looking for things like dungeon walls and shit like that.[/QUOTE]
- Make them
- Free assets on asset store
- opengameart.org
- Search "free 3d models"
- Sketchup warehouse
Don't expect to ever find what you're looking for for free. You might find something similar and passable, but you need to work with / hire an artist or learn the skills yourself to get (closer to) exactly what you want.
Ditched the board game part idea, kept the Dice in to be used as another component of the game. Add a fair bit of the backbone to the code, and language support right off the bat so I don't have to dick around with that later.
[t]http://i.imgur.com/dSgvKSG.png[/t]
[QUOTE=MokTok;44196785]- Make them
- Free assets on asset store
- opengameart.org
- Search "free 3d models"
- Sketchup warehouse
Don't expect to ever find what you're looking for for free. You might find something similar and passable, but you need to work with / hire an artist or learn the skills yourself to get (closer to) exactly what you want.[/QUOTE]
Yeah I understand I need an artist eventually but not for a college project ha that's why I was wondering if anybody here had any place that they routinely use for assets
FMOD is now free for indie teams, and a Unity SDK was released.
[quote=Firelight Technologies]Firelight Technologies announced today that its next generation audio tool suite, FMOD Studio, is now free for indie developers. FMOD Studio has always been free for non-commercial projects, and from today it will also be free for commercial indie projects.[/quote]
[url=http://www.fmod.org/fmod-now-free-for-indies/]http://www.fmod.org/fmod-now-free-for-indies/[/url]
Download it here: [url=http://www.fmod.org/download/]http://www.fmod.org/download/[/url]
Unity Documentation: [url=http://www.fmod.org/forum/viewtopic.php?f=30&t=16159]Here[/url] (Use link on the post)
Example Setup: [url=http://www.fmod.org/forum/viewtopic.php?f=30&t=18688]Here[/url]
FMOD GitHub: [url=https://github.com/fmod]Here[/url] (Nothing on it yet)
[QUOTE=NinjaWilko;44200313]FMOD is now free for indie teams, and a Unity SDK was released.
[url=http://www.fmod.org/fmod-now-free-for-indies/]http://www.fmod.org/fmod-now-free-for-indies/[/url]
Download it here: [url=http://www.fmod.org/download/]http://www.fmod.org/download/[/url]
Unity Documentation: [url=ftp://ftp.fmod.org/FMOD%20Studio%20Unity%20Integration.pdf]Here[/url]
Example Setup: [url=http://www.fmod.org/forum/viewtopic.php?f=30&t=18688]Here[/url]
FMOD GitHub: [url=https://github.com/fmod]Here[/url] (Nothing on it yet)[/QUOTE]
Nice! But Documentation link is asking for User/Pass
[QUOTE=Huabear;44200354]Nice! But Documentation link is asking for User/Pass[/QUOTE]
Try accessing it through here:
[url=http://www.fmod.org/forum/viewtopic.php?f=30&t=16159]http://www.fmod.org/forum/viewtopic.php?f=30&t=16159[/url]
Sorry, you need to Log In to post a reply to this thread.