• Unity3D - Discussion
    5,004 replies, posted
Jesus Garry.. Looks like you're having fun.
Picking up things: [video=youtube;vhflx4mbAFs]http://www.youtube.com/watch?v=vhflx4mbAFs[/video] Not that great. The physics are a little wonky. How could I make something more like hl2?
[QUOTE=Pelf;40362391]Picking up things: [video=youtube;vhflx4mbAFs]http://www.youtube.com/watch?v=vhflx4mbAFs[/video] Not that great. The physics are a little wonky. How could I make something more like hl2?[/QUOTE] I like it, though. Here's what HL2 did... When you picked something up in HL2, it would snap to the crosshair and try to stay unless there was something in the way. Some objects would right themselves up. The yaw of the object was kept so that it always faced you in the same direction you picked it up. When you looked up and down, the pitch of the object never changed.
[THUMB]http://i.imgur.com/SKHAcXt.png[/THUMB] I decided to post my project folder. Is it organized well?
Got picking up objects working pretty nicely. Still kinda wonky with higher mass objects (10x player mass for example). You can throw them and you'll push yourself back if it's a heavy object. [video=youtube;9yH_mpO3GTo]http://www.youtube.com/watch?v=9yH_mpO3GTo[/video] [sp]it's a really heavy feather[/sp]
[QUOTE=Pelf;40371639]Got picking up objects working pretty nicely. Still kinda wonky with higher mass objects (10x player mass for example). You can throw them and you'll push yourself back if it's a heavy object. [sp]it's a really heavy feather[/sp][/QUOTE] Have you seen this video? (It's an hour long, get comfy..) [video=youtube;afBm0Dpfj_k]http://www.youtube.com/watch?v=afBm0Dpfj_k[/video]
Pro-tips of the day: 1. Reference everything you're going to use more than once in a class, seriously if you notice you're using GetComponent or transform a lot, make a reference for those and use it instead, I went from 140FPS to 300FPS just from doing this in 3 classes, and they weren't even that big. 2. If you are calculating something repeatedly but don't need it to calculate every frame, think about using InvokeRepeating instead of Update, LateUpdate or FixedUpdate, by spreading influences in my AI graph through InvokeRepeating I went from those 300FPS I had when running it on Update to 1400FPS and it still works flawlessly.
[QUOTE=DeanWinchester;40372227]Pro-tips of the day: 1. Reference everything you're going to use more than once in a class, seriously if you notice you're using GetComponent or transform a lot, make a reference for those and use it instead, I went from 140FPS to 300FPS just from doing this in 3 classes, and they weren't even that big. 2. If you are calculating something repeatedly but don't need it to calculate every frame, think about using InvokeRepeating instead of Update, LateUpdate or FixedUpdate, by spreading influences in my AI graph through InvokeRepeating I went from those 300FPS I had when running it on Update to 1400FPS and it still works flawlessly.[/QUOTE] Wow, uncapping the FPS fucked everything up for me because of my usage of Time.deltaTime. Good thing I found out the issue now.
To add to the data hiding vs exposing variables to the editor discussion earlier, I always use [code][SerializeField] private int foo;[/code] to mark variables so they are exposed to the editor and allow me to keep my data hiding.
So I've been working on a game project for my university freshman design class. It's gonna be a top-down scrolling shooter with FTL's traveling between planets/getting upgrades gimmick. I had to write script that would read enemy formations from a text file and spawn them in time. I also had to encode movement patterns that change per ship/formation along with the firing patterns. It was a disaster. [code] #pragma strict import System.IO; var fileName = "testSequence1.txt"; var listOfObjects; //var SpawnList : int[,]; var SpawnList = new ArrayList(); var timeStep : float = 0; var timeElapsed : float = 0; var TimedEvent : boolean = true; var yStepCount : int = 0; var SpawnList_counter : int = 0; var SpawnList_xSize : int; var SpawnList_ySize : int; private var timeOffset : float = 0; private var debug : boolean = false; // public var SpawnPlane1 : GameObject; public var Plane1Name : String = "Fighter"; public var SpawnPlane2 : GameObject; public var Plane2Name : String = "Scout"; public var SpawnPlane3 : GameObject; public var Plane3Name : String; public var SpawnPlane4 : GameObject; public var Plane4Name : String; public var SpawnPlane5 : GameObject; public var Plane5Name : String; public var SpawnPlane6 : GameObject; public var Plane6Name : String; public var SpawnPlane7 : GameObject; public var Plane7Name : String; public var SpawnPlane8 : GameObject; public var Plane8Name : String; public var SpawnPlane9 : GameObject; public var Plane9Name : String; public var SpawnPlane10 : GameObject; public var Plane10Name : String; private var stillNotMore : boolean = true; function Start() { //PlayPlanetSequence("planetSequence1.txt"); LoadSpawnList("planetSequence1.txt"); SortArrayList(); if(debug) debugShowWave(); } function FixedUpdate() { if(SpawnList.Count > 0) { BatchSpawn(); } } function BatchSpawn() { var item1 : shipSpawnData = SpawnList[0]; var newToSpawn = item1.getSpawnTime() <= Time.time; var counter : int = 0; while(item1.getSpawnTime() <= Time.time) { counter++; item1 = SpawnList[counter]; } for(var i = 0; i < counter; i++) { item1 = SpawnList[i]; SpawnPlane(item1); } for(i = 0; i < counter; i++) { SpawnList.RemoveAt(0); } } function SpawnPlane(data : shipSpawnData) { if(data.shipType != "N") { var ixe : float = 0; if(debug) { ixe = data.getSpawnTime() * 6; } var spawnedPlane : GameObject = parseShipType(data.shipType); spawnedPlane = Instantiate(spawnedPlane,Vector3(data.xSpawnPos,45+data.ySpawnPos+ixe,0), transform.rotation); spawnedPlane.GetComponent(EnemyController).movementString = data.movementString; spawnedPlane.GetComponent(EnemyController).fireString = data.fireString; } } function LoadSpawnList(fileName : String) { var appDataPath = Application.dataPath.Replace("/", "\\"); var reader1 = new StreamReader(appDataPath + "\\" + fileName); var fileContent = reader1.ReadToEnd(); var lines = fileContent.Split("\n"[0]); reader1.Close(); for(line in lines) { line = line.Replace("\r", ""); if(line.length > 1) { LoadPlanetSequence(line); } } } function LoadPlanetSequence(fileName : String) { var appDataPath = Application.dataPath.Replace("/", "\\"); var filePath : String = (appDataPath + "\\" + fileName); Debug.Log(filePath); var reader1 = new StreamReader(filePath); var fileContent = reader1.ReadToEnd(); var lines = fileContent.Split("\n"[0]); reader1.Close(); //shipSpawnData(spawnTime_ : float, shipType_ : String, movementString_ : String, fireString_ : String, xSpawnPos_ : float) for(line in lines) { if(line[0] != '#') { var parts = line.Split(" "[0]); var spawnTime_ : float = parseFloat(parts[0]) + timeOffset; var shipType_ : String= parts[1]; var movementString_ : String = parts[2]; var fireString_ : String = parts[3]; var xSpawnPos_ : float= parseFloat(parts[4]); var ySpawnPos_ : float= parseFloat(parts[5]); /*Debug.Log("Delay: " + spawnTime_); Debug.Log("Ship Type: " + shipType_); Debug.Log("movementString: " + movementString_); Debug.Log("fireString: " + fireString_); Debug.Log("xSpawnPos: " + xSpawnPos_);*/ var shipData = new shipSpawnData(spawnTime_, shipType_, movementString_, fireString_, xSpawnPos_, ySpawnPos_); SpawnList.Add(shipData); //Debug.Log("Count : " + SpawnList.Count); } } timeOffset = SpawnListGetMaxTime(); } function SpawnListGetMaxTime() { var maxTime : int = 0; var biggestLoc : int = 0; for(var j = 0; j < SpawnList.Count; j++) { var item1 : shipSpawnData = SpawnList[biggestLoc]; Debug.Log("item1 spawn time: " + item1.getSpawnTime()); var item2 : shipSpawnData = SpawnList[j]; Debug.Log("item2 spawn time: " + item2.getSpawnTime()); if(item1.getSpawnTime() <= item2.getSpawnTime()) { maxTime = item2.getSpawnTime(); Debug.Log("New Max: " + maxTime); } } Debug.Log("Final Max: " + maxTime); return maxTime; } function SortArrayList() { var SpawnListOrdered = new ArrayList(); var maxCount : int = SpawnList.Count; var orderCount : int = 0; var smallestLoc : int = 0; while(SpawnList.Count > 0 && orderCount < (maxCount)) { for(var l = 0; l < SpawnList.Count; l++) { var item1 : shipSpawnData = SpawnList[smallestLoc]; var item2 : shipSpawnData = SpawnList[l]; if(item1.getSpawnTime() > item2.getSpawnTime()) { smallestLoc = l; } } SpawnListOrdered.Add(SpawnList[smallestLoc]); SpawnList.RemoveAt(smallestLoc); smallestLoc = 0; orderCount++; } //SpawnListOrdered.Add(SpawnList[0]); for(var j = 0; j < SpawnList.Count; j++) { var thisItem : shipSpawnData = SpawnList[j]; //Debug.Log("UL Spawn Time: " + thisItem.getSpawnTime()); } SpawnList = SpawnListOrdered; for(j = 0; j < SpawnList.Count; j++) { var thisItem2 : shipSpawnData = SpawnList[j]; //Debug.Log("OD Spawn Time: " + thisItem2.getSpawnTime()); } } function debugShowWave() { var spawnedPlane : GameObject; for(var i = 0; i < SpawnList.Count; i++) { var thisItem : shipSpawnData = SpawnList[i]; SpawnPlane(thisItem); } //Time.timeScale = 0; } function parseShipType(input : String) { switch(input) { case Plane1Name: return SpawnPlane1; break; case Plane2Name: return SpawnPlane2; break; case Plane3Name: return SpawnPlane3; break; case Plane4Name: return SpawnPlane4; break; case Plane5Name: return SpawnPlane5; break; case Plane6Name: return SpawnPlane6; break; case Plane7Name: return SpawnPlane7; break; case Plane8Name: return SpawnPlane8; break; case Plane9Name: return SpawnPlane9; break; case Plane10Name: return SpawnPlane10; break; default: return SpawnPlane1; } } class shipSpawnData { public var spawnTime : float = 0; public var shipType : String = ""; public var movementString : String = ""; public var fireString : String = ""; public var xSpawnPos : float = 0; public var ySpawnPos : float = 0; function shipSpawnData(spawnTime_ : float, shipType_ : String, movementString_ : String, fireString_ : String, xSpawnPos_ : float, ySpawnPos_ : float) { spawnTime = spawnTime_; shipType = shipType_; movementString = movementString_; fireString = fireString_; xSpawnPos = xSpawnPos_; ySpawnPos = ySpawnPos_; } function getSpawnTime() { return spawnTime; } } [/code]
Playing with the mic [url]https://vine.co/v/bPJ9KKuwLtx?fb_action_ids=10151621903005833&fb_action_types=vine-app%3Apost&fb_source=aggregation&fb_aggregation_id=288381481237582[/url]
did you make that on 4/20 by any chance garry
Anyone have any links on how to use Unity's built in animation editor? I don't even know how/where to find it.
[QUOTE=Pelf;40413214]Anyone have any links on how to use Unity's built in animation editor? I don't even know how/where to find it.[/QUOTE] Theres this one for the "old" animation system: [url=http://docs.unity3d.com/Documentation/Components/AnimationEditorGuide.html]http://docs.unity3d.com/Documentation/Components/AnimationEditorGuide.html[/url]
The animation system is kind of fiddly. I am desperate for a shortcut that plays the animation - then when you press it again stops playing it and returns you to where you were.
If I'm not mistaken, the old animation system(Animation) is going to be phased out (but not in 4.x), replaced by Mecanim(Animator) when Mecanim is fully ready (supports Humanoid, not sure about Generic animations). Mecanim still has long way to go to replace the old animation system (lacking lots of stuff like event system, but someone made a paid plugin for that) but its easy as hell to use to make animations for player/enemy characters. Anybody used HOTween or iTween before? Can I know how it makes life easier with it cause I'm clueless and dumb.
So this animation system is going to be totally replaced?
From [url=http://forum.unity3d.com/threads/155061-Does-Mecanim-deprecate-the-old-animation-system]the official forum reply (June 2012)[/url] the creative programmer said that there was no active development on the old animation system and will be phased out when the time comes, and in the comment section from a [url=http://blogs.unity3d.com/2012/06/20/more-mecanim/]blog entry 10 months ago[/url] one of the developer said it remains for now. [url=http://docs.unity3d.com/Documentation/Manual/MecanimAnimationSystem.html]Mecanim's official manual[/url] stated: [quote][b]Legacy animation system[/b] While Mecanim is recommended for use in most situations, especially for working humanoid animations, the Legacy animation system is still used in a variety of contexts. One of them is working legacy animations and code (content created before Unity 4.0). Another is controlling animation clips with parameters other than time (for example for controlling the aiming angle). For information on the Legacy animation system, see this section Unity intends to phase out the Legacy animation system over time for all cases by merging the workflows into Mecanim.[/quote] However, Mecanim still has a long way to go to completely replace the Legacy AnimationSystem, so its pretty much safe to use it (like Shuriken and Legacy ParticleSystem).
[QUOTE=secundus;40416710]If I'm not mistaken, the old animation system(Animation) is going to be phased out (but not in 4.x), replaced by Mecanim(Animator) when Mecanim is fully ready (supports Humanoid, not sure about Generic animations). Mecanim still has long way to go to replace the old animation system (lacking lots of stuff like event system, but someone made a paid plugin for that) but its easy as hell to use to make animations for player/enemy characters. Anybody used HOTween or iTween before? Can I know how it makes life easier with it cause I'm clueless and dumb.[/QUOTE] ITween is a fairly comprehensive code driven animation system, it adds components to objects which animated them, and you specify the animation when you add components, you can also premake animation paths and then add them with the components. I mostly use it for Push and Punch Position/Rotation functions, nice snappy little jiggle animations with minimal code.
I'm making a total conversion of "Desperate Gods" for Arkham Horror, an awesome board game. Desperate Gods was a game made for a game jam by [URL="http://www.wolfire.com/"]Wolfire Games[/URL]. I can't distribute this, yet at least. Once it is playable I will talk to the devs and see if I can make it available for free ( they are very strict on their licensing because they have been screwed over once before ). Anyway here it is. The cards and board are very legible when you zoom in using the Z key. Any tips on how to increase the texture quality? I already set them to Advanced, Trilinear, and they are generating mip maps. [IMG]http://i.imgur.com/VMV4tK3.jpg[/IMG]
Try increasing the anisotropic filtering value, or setting a [url=http://docs.unity3d.com/Documentation/ScriptReference/Texture-mipMapBias.html]negative mipmap bias[/url], or apparently Unity's autogenerated mipmaps can optionally have a different downscaling algorithm: "A sharpening Kaiser algorithm is run on the mip maps as they go down in size. If your textures are too blurry in the distance, try this option." (as opposed to box filtering.)
[QUOTE=slime73;40424267]Try increasing the anisotropic filtering value, or setting a [url=http://docs.unity3d.com/Documentation/ScriptReference/Texture-mipMapBias.html]negative mipmap bias[/url], or apparently Unity's autogenerated mipmaps can optionally have a different downscaling algorithm: "A sharpening Kaiser algorithm is run on the mip maps as they go down in size. If your textures are too blurry in the distance, try this option." (as opposed to box filtering.)[/QUOTE] Thanks. This helped a bit :)
Making 'paper physics' (not real life paper it would be boring as fuck) is a pain, this is an old video though [video=youtube;1KdYU1S6Yco]http://www.youtube.com/watch?v=1KdYU1S6Yco[/video]
[QUOTE=CrashLemon;40426303]Making 'paper physics' (not real life paper it would be boring as fuck) is a pain, this is an old video though [video=youtube;1KdYU1S6Yco]http://www.youtube.com/watch?v=1KdYU1S6Yco[/video][/QUOTE] You should make it do loops when it blows left and right.
Anyone got any good book recommendations for using C with Unity? Beginners stuff
[QUOTE=Neddy;40432006]Anyone got any good book recommendations for using C with Unity? Beginners stuff[/QUOTE] I don't think you'll find a lot of stuff for C with Unity.
[QUOTE=Neddy;40432006]Anyone got any good book recommendations for using C with Unity? Beginners stuff[/QUOTE] You probably mean C#? Because you cannot use C with Unity.
[QUOTE=Simspelaaja;40432583]You probably mean C#? Because you cannot use C with Unity.[/QUOTE] Yeah C# Sorry. My keyboard didn't appear to type the hash.
[QUOTE=Simspelaaja;40432583]You probably mean C#? Because you cannot use C with Unity.[/QUOTE] You could if you tried hard enough :v:
This is probably a pretty simple thing to do but: until now, for going to locations on a planet, I had a cube gameobject whose name was the name of the level so if the player double clicked on it, it would do [i]Application.LoadLevel(hitInfo.collider.name);[/i] so that I wouldn't have to write a script for it. How could I do a similar thing for a GUI texture icon? [img]https://dl.dropboxusercontent.com/u/13781308/ShareX/2013-04/icon.png[/img] PlanetscreenIcon.cs goes on all icon gameobjects: [CODE]using UnityEngine; using System.Collections; public class PlanetscreenIcon : MonoBehaviour { public Texture2D iconImage; bool isInLineOfSight; Vector2 screenPos; void Update() { if ( Physics.Linecast(transform.position, Camera.main.transform.position) == false ) isInLineOfSight = true; else isInLineOfSight = false; } void OnGUI() { if ( isInLineOfSight == true) DisplayIcon(); } void DisplayIcon() { screenPos = Camera.main.WorldToScreenPoint(transform.position); float guiPosX = screenPos.x - ( iconImage.width / 2 ); float guiPosY = ( Screen.height - screenPos.y ) - ( iconImage.height / 2 ); Rect guiRect = new Rect(guiPosX, guiPosY, 22, 22); GUI.Label(guiRect, iconImage); } } [/CODE] Checking if the player double clicks: [code]if ( Input.GetKeyDown(KeyCode.Mouse0) && canClick == true ) { if ( ( Time.time - doubleClickStart ) < 0.3f ) { OnDoubleClick(); doubleClickStart = -1; } else { doubleClickStart = Time.time; } }[/code] Double clicking: [code]void OnDoubleClick() { Ray mouseClickRay = Camera.mainCamera.ScreenPointToRay(Input.mousePosition); // Declaring the ray RaycastHit hitInfo; // Declaring the raycast info dump Physics.Raycast(mouseClickRay, out hitInfo, 1000.0f); // Casting the ray if ( hitInfo.collider.tag == "Planet" && isCameraMoving == false ) { cameraMovePosition = hitInfo.collider.transform.position; cameraDistanceToMovePosition = Vector3.Distance(transform.position, cameraMovePosition); StartCoroutine(MoveCameraCoroutine()); } else if ( hitInfo.collider.tag == "Location Marker" && isCameraMoving == false ) // The old way I was doing it { Application.LoadLevel(hitInfo.collider.name); } }[/code]
Sorry, you need to Log In to post a reply to this thread.