Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pilchenstein
May 17, 2012

So your plan is for half of us to die?

Hot Rope Guy
I started tooling around in Unity yesterday and I think I'm misunderstanding something fundamental somewhere. I've made a project with a sprite that you can move around, the script for which is this:
code:
using UnityEngine;
using System.Collections;

public class NewBehaviourScript1 : MonoBehaviour {

	float xSpeed = 10f;
	float ySpeed = 10f;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		float xMove = Input.GetAxis ("Horizontal") * xSpeed;
		float yMove = Input.GetAxis ("Vertical") * ySpeed;

		float xTrans = xMove * Time.deltaTime;
		float yTrans = yMove * Time.deltaTime;

		transform.Translate (xTrans, yTrans, 0f);
	}
}
However, when you move it around, it seems to have inertia - it takes a second to get going and a second to stop after you stop pushing inputs. Have I stuffed up the script somehow (this is my first experience with C#) or should I be using FixedUpdate() instead?

Adbot
ADBOT LOVES YOU

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Pilchenstein posted:

However, when you move it around, it seems to have inertia - it takes a second to get going and a second to stop after you stop pushing inputs. Have I stuffed up the script somehow (this is my first experience with C#) or should I be using FixedUpdate() instead?
That's something to do with the GetAxis function - in trying to make keys perform like Axes it does a little "gradual change" thing over a couple of frames. If you want immediate response use GetAxisRaw, which omits the smoothing.

Edit: GetAxisRaw also doesn't even do the "you were pressing the input for half a frame" math that would make it actually good. :(
Don't know if GetAxis does any of that either, or if it just smooths in an unpredictable way.

Also if you want a little bit of smoothing you can change the rise/fall values for GetAxis in the Input Manager.

roomforthetuna fucked around with this message at 16:26 on Nov 19, 2013

Pilchenstein
May 17, 2012

So your plan is for half of us to die?

Hot Rope Guy

roomforthetuna posted:

That's something to do with the GetAxis function - in trying to make keys perform like Axes it does a little "gradual change" thing over a couple of frames. If you want immediate response use GetAxisRaw, which omits the smoothing.

Edit: GetAxisRaw also doesn't even do the "you were pressing the input for half a frame" math that would make it actually good. :(
Don't know if GetAxis does any of that either, or if it just smooths in an unpredictable way.

Also if you want a little bit of smoothing you can change the rise/fall values for GetAxis in the Input Manager.

GetAxisRaw makes it behave like I was expecting, so thanks for that. It does occasionally seem to jump when you're moving around now though, like it's dropped a few frames - is that something to do with getting the raw input or is playing stuff inside the editor prone to the odd stutter? I've literally only got the one sprite in the scene so far, so performance shouldn't be an issue.

czg
Dec 17, 2005
hi

devilmouse posted:

We keep our source in git(hub) and our assets in Perforce and everything moves along swimmingly.
This is how we do it too, and it works great.

roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!
Little update on new Unity, there seems to be a bug wherein you can't do rigidbody2D.mass=n; - it compiles and runs but the mass doesn't change. Which is a bit of a bugger for dynamically generated objects. Can't even generate a component from a prefab, only a whole object, so it's a pain in the rear end to work around too.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Out of curiosity, how well does Unity handle stuttering issues for fixed timestep updates? I know that they recommend setting the 'interpolated' mode on the main character (and I assume that they always interpolate the camera), but what about other things, like slow moving projectiles? I know that if I don't interpolate frames in my own engine with a delta time of 1/60, I get stuttering on all sorts of things, not just the player. Anyone have experience with this?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Orzo posted:

Out of curiosity, how well does Unity handle stuttering issues for fixed timestep updates? I know that they recommend setting the 'interpolated' mode on the main character (and I assume that they always interpolate the camera), but what about other things, like slow moving projectiles? I know that if I don't interpolate frames in my own engine with a delta time of 1/60, I get stuttering on all sorts of things, not just the player. Anyone have experience with this?

From my limited experience, I'd say OK as long as you aren't make huge jumps in position. Also note that what you see when you play in the editor is a bit different then a real build. I've noticed increased smoothness in web builds compared to in editor. Building to PC is the same. For some reason, the editor just likes to stutter.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Yeah there are definitely quick effects and such in Drive to Hell that I can barely see in the editor that are just fine in builds. I just figured it was because building optimizes things on top of not having the editor's overhead.

Above Our Own
Jun 24, 2009

by Shine

devilmouse posted:

The biggest is that it handles the large binary files that games tend to generate without issue or having to jump through any hoops (. Then things get murkier...

It seems every time we use git/hg, a non-technical person (artists and designers) always seem to muck something up because the DVCS model confuses them. If your engineers strongly leverage the branching models, the less technical folk will get tripped up and invariably screw something up. Perforce is a much easier beast for them to wrap their heads around.

Supposedly, Unity 4.3 has Perforce integration as well, but I can't speak to how good/bad it is since we haven't moved to 4.3 yet.

We keep our source in git(hub) and our assets in Perforce and everything moves along swimmingly.
I'm the only coder on our team, the others are doing media. Thinking about non-technical people using VCS and the headaches that can cause, I might go for something super simple because realistically I only need to be able to sync media assets. I'm thinking SVN for this, I would consider Perforce/PlasticSCM but I really don't want to shell out $500/seat for the team licenses and SVN has cheap Unity plugins I'm hoping are decent.

One Eye Open
Sep 19, 2006
Am I awake?

Meridian Rizing posted:

This isn't directly game development related but it involves Unity and mesh and geometry reduction.

I've been working on a project that involves taking large (6,000,000 verts, at least, upwards to 20,000,000. About 50,000 separate meshes at least) models generated from a CAD application and putting them into a model viewer in Unity that can then be exported for a web build. The geometry is unoptimised. Horribly. The default exporter from the CAD program doesn't index or instance geometry, these both had to be done in a custom exporter. I’m looking into ways of speeding this up further. At present in the Unity model viewer geometry is combined on startup from these smaller meshes to reduce the number of draw calls to a sane number. There no other real consideration other than the number of vertices. The model is rendered with vertex colouring and there is no other shading or lighting to speak of other than simple diffuse.

I’m looking into several approaches to increase the framerate, both offline in the export step and in Unity and I wanted some input on a couple of problems I’m facing.

Firstly mesh reduction-- I have adapted an implementation of the Stan Melax Polychop algorithm. It’s effective on a lot of the meshes especially pipes (which have so many vertices that they look smooth with vertex lighting). However some meshes have absolutely horrendous topology, I think they might have been modeled using boolean addition and subtraction, there also appears to be a lot of overlapping geometry. When applying Polychop to these meshes the normals get all warped and inverting leading to back faces becoming front faces, incorrect lighting, z-fighting, occasionally the algorithm will exception etc,etc. I have a couple of thoughts about what to do with this, I could try to manually recalculate the normals based on the old normals. Alternatively I could attempt to clean up the meshes topology, attempting to weld vertices together and trying to retopologize the mesh, but I am not sure on where to start on such an exercise. Finally I could try applying Polychop only to meshes that are cylindrical. But I’m not sure where to start on taking an arbitrary collection of vertices and indices and and working out if they form a cylinder.

Secondly Unity Pro features (Static batching/occlusion culling) -- I just got my hands on Unity pro today and there are two features I had a very cursory experiment with. Static batching and occlusion culling. I tried using StaticBatchingUtility today but it did not appear to have any effect on the frame rate. Reading up on it, appears that I am already doing a form of static batching by combining meshes. Does the static batching that Unity performs offer any benefit over what I am doing? Regarding occlusion culling, will it handle my irregular shaped and positioned combined meshes well? What’s the memory footprint like, and time required to bake the maps like?

Finally and sort of related to the above-- Mesh grouping. The one thing the CAD file has going for it is that it roughly grouped it’s geometry by subsystem and floor. At present meshes are combined in the order that they are read into the Unity meaning that a given mesh could cover quite a large area of different systems in world. Would there be anything to be gained by grouping meshes by floor and subsystem, in terms of general performance or with regard to occlusion culling.

Any thoughts on any of this would be greatly appreciated.

You could use MeshLab to cleanup/reduce your meshes before importing into Unity.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
I'm so loving sick of the crap version of Monodevelop that Unity ships with that I'm installing Xamarin again. Of course it being the same goddamn thing it can't help but sucking fat loving balls at everything it does so now I have duplicate mono frameworks installed on my system along with duplicate Android SDKs because Xamarin is too goddamn dumb to use the one I already have.

:waycool:

But seriously HOW DO YOU gently caress UP AN IDE THIS BADLY. Command-A for select all is a no brainer to support and not only does Monodevelop break sometimes and switch that command to be build but it NEVER allows it in other text fields in the editor like search boxes and such. Why the hell not? Who made this poo poo?

Dirty
Apr 8, 2003

Ceci n'est pas un fabricant de pates
I've not installed it yet, but Unity 4.3 ships with a much newer version of Monodevelop.

Zizi
Jan 7, 2010

Dirty posted:

I've not installed it yet, but Unity 4.3 ships with a much newer version of Monodevelop.

It also seems to be a much more broken version! :v:

Dirty
Apr 8, 2003

Ceci n'est pas un fabricant de pates

Zizi posted:

It also seems to be a much more broken version! :v:

Then perhaps I'll keep holding off on that install!

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Yeah I don't get it. Monodevelop technically doesn't exist any more, it's been rebranded as Xamarin Studio as of what would have been Monodevelop 4. But somehow Unity managed to convince them (or something?) to include a custom build which is nothing but an out-of-date version of Xamarin rebranded back to being Monodevelop. It's baffling.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Yodzilla posted:

Yeah I don't get it. Monodevelop technically doesn't exist any more, it's been rebranded as Xamarin Studio as of what would have been Monodevelop 4. But somehow Unity managed to convince them (or something?) to include a custom build which is nothing but an out-of-date version of Xamarin rebranded back to being Monodevelop. It's baffling.

I love how default settings is tabs out to 8 and you can't tab to indent past brackets anymore. Hit Ctrl-S to convert all your code to poo poo! I'm probably going to grab my old install of Unity just so I can use the old monodevelop with 4.3.

xzzy
Mar 5, 2009

Dirty posted:

Then perhaps I'll keep holding off on that install!

But the rest of the enhancements are pretty drat sweet.

I skirt around the monodevelop issue by using vi. :colbert:

Marsol0
Jun 6, 2004
No avatar. I just saved you some load time. You're welcome.

xzzy posted:

I skirt around the monodevelop issue by using vi. :colbert:

I haven't done much with Unity yet. I just installed it two days ago and haven't had time to play with it. But, I just use vim GUI with Omnisharp plugin installed. Seems to work well enough.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
I hope ya'll are on non-Windows machines, all this talk about developing C# code in an IDE that isn't Visual Studio.

xzzy
Mar 5, 2009

Orzo posted:

I hope ya'll are on non-Windows machines, all this talk about developing C# code in an IDE that isn't Visual Studio.

I write code on mac, linux, AND windows machines.

xcode is probably my favorite IDE, but vi is overall easier because there's no IDE that I like that runs on all three platforms.

Orzo
Sep 3, 2004

IT! IT is confusing! Say your goddamn pronouns!
Yeah that's cool, I was just making the assertion that if your primary dev workstation is Windows AND you're writing C#, you should be using Visual Studio and not some monodevelop garbage.

Out of curiosity, why do you use all 3? Do you not have a primary workstation, or are you talking about different jobs/hobbies?

Obsurveyor
Jan 10, 2003

Orzo posted:

Yeah that's cool, I was just making the assertion that if your primary dev workstation is Windows AND you're writing C#, you should be using Visual Studio and not some monodevelop garbage.

You still can't debug/set breakpoints for Unity outside of MonoDevelop can you?

xzzy
Mar 5, 2009

Orzo posted:

Out of curiosity, why do you use all 3? Do you not have a primary workstation, or are you talking about different jobs/hobbies?

Work machine/laptop is a mac, home machine is Windows, and the linux machine is mostly there to test compatibility. I don't actually do much Unity work on Linux, though I technically could because it has access to all my project folders.

It's also my go-to environment for tinkering with new ideas, usually in python. OSX has a nice python install but it's a pain in the rear end under windows, so I just ssh into the linux box and do everything there.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

xzzy posted:

xcode is probably my favorite IDE

Look at this guy and his terrible opinions :smuggo:

Unormal
Nov 16, 2004

Mod sass? This evening?! But the cakes aren't ready! THE CAKES!
Fun Shoe

Obsurveyor posted:

You still can't debug/set breakpoints for Unity outside of MonoDevelop can you?

UnityVS fully integrates debugging with visual studio. The only problem I've had with it is that complex variable watches don't always seem to work correctly.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

Orzo posted:

Yeah that's cool, I was just making the assertion that if your primary dev workstation is Windows AND you're writing C#, you should be using Visual Studio and not some monodevelop garbage.

Out of curiosity, why do you use all 3? Do you not have a primary workstation, or are you talking about different jobs/hobbies?

I have a Windows machine at work, a Windows machine in my office at home that I do my side stuff on + gaming and a MacBook Pro that I use for my iOS development and work on the go. I've got Windows 8 on it as well and I could do my Unity work in there but I'd rather not as I'm making a mobile game and need the whole iOS/Xcode stuff all the drat time. That's when I use Monodevelop/Xamarine.

Xcode is fine for doing native Objective-C stuff but I wouldn't touch it for anything else.

xgalaxy
Jan 27, 2004
i write code

Yodzilla posted:

I have a Windows machine at work, a Windows machine in my office at home that I do my side stuff on + gaming and a MacBook Pro that I use for my iOS development and work on the go. I've got Windows 8 on it as well and I could do my Unity work in there but I'd rather not as I'm making a mobile game and need the whole iOS/Xcode stuff all the drat time. That's when I use Monodevelop/Xamarine.

Xcode is fine for doing native Objective-C stuff but I wouldn't touch it for anything else.

Xcode is much better at C and C++ then Visual Studio.

captain_g
Aug 24, 2007

xgalaxy posted:

Xcode is much better at C and C++ then Visual Studio.

But my ~find in files~ and ~comfort zone~!!!

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
I haven't coded in C or C++ in years so I'll take your word for it. :colbert:

Dirty
Apr 8, 2003

Ceci n'est pas un fabricant de pates

Orzo posted:

I hope ya'll are on non-Windows machines, all this talk about developing C# code in an IDE that isn't Visual Studio.

I just used what Unity threw at me because at the time I wasn't really sure where everything was, or how using a non-Unity provided IDE would work. And I started off with UnityScript.

I've just finished porting my project over to C#, though, so I don't really have an excuse now.

I quite often start coding by double-clicking a script in Unity. I'm not exactly wedded to that particular action, but out of curiosity is it possible to configure Unity to send you to a preferred IDE instead? Or should I just be firing up Visual Studio myself?

captain_g
Aug 24, 2007

Dirty posted:

I just used what Unity threw at me because at the time I wasn't really sure where everything was, or how using a non-Unity provided IDE would work. And I started off with UnityScript.

I've just finished porting my project over to C#, though, so I don't really have an excuse now.

I quite often start coding by double-clicking a script in Unity. I'm not exactly wedded to that particular action, but out of curiosity is it possible to configure Unity to send you to a preferred IDE instead? Or should I just be firing up Visual Studio myself?

That depends:
http://docs.unity3d.com/Documentation/Manual/VisualStudioIntegration.html

Yes, if you have Visual Studio Professional.

Rottbott
Jul 27, 2006
DMC

xgalaxy posted:

Xcode is much better at C and C++ then Visual Studio.
Nope. Did they add a way to compile a single file yet?

Sgt. Raisins
Oct 21, 2007
Damnit
What about any decent autocomplete for Sublime Text? The monodev text editor is terrible.
Edit: or even an addin to just allow better text and file manipulation. Multi Cursors, Multi Highlighting, folder/open files list/viewer

Sgt. Raisins fucked around with this message at 20:42 on Nov 20, 2013

devilmouse
Mar 26, 2004

It's just like real life.

Sgt. Raisins posted:

What about any decent autocomplete for Sublime Text? The monodev text editor is terrible.

Depending on who you talk to here, we use ST3, Vim, or Emacs. All of them have enough auto-complete support through various packages to allow you to be as lazy as you want with Unity.

Above Our Own
Jun 24, 2009

by Shine
Last few posts have definitely talked me into picking up UnityVS.

Shalinor
Jun 10, 2002

Can I buy you a rootbeer?

Orzo posted:

Yeah that's cool, I was just making the assertion that if your primary dev workstation is Windows AND you're writing C#, you should be using Visual Studio and not some monodevelop garbage.

Out of curiosity, why do you use all 3? Do you not have a primary workstation, or are you talking about different jobs/hobbies?
UnityVS is expensive, therefore, I use MonoDevelop. :colbert:

... but mostly because I switch between Win and OSX sometimes, and I hate my tools changing when I do. Currently planning to move over to the Mac for mainline dev, since the iMac is waaaay faster than my aging laptop :geno:

Corbeau
Sep 13, 2010

Jack of All Trades
Okay, I didn't get any suggestions from the making games thread, so I'll ask here with a bit more detail.

I'm currently working on basic interface in Unity for Android, and am having... not really a problem, but an unexpected behavior that's annoying. My game involves a 3D map that the player can navigate via dragging the terrain around (on PC, as you can try here, it's click+drag). This works flawlessly in the PC web player version, but the movement has a delay in the Android version using my tablet's touchscreen (it's a Nexus 10, if that matters). I don't know whether this is inherent to touchscreens, since my experience with them in a gaming context is pretty minimal, or if there's something in Unity and/or my code that's adding the delay. Again, the PC version is completely responsive and uses almost exactly the same code, so I'm quite confused.

All that my script does is remember when the mouse is held down or a particular touch is maintained, remembering the previous location of the mouse or touch, and then raycast against a horizontal backdrop plane in order to determine how much to move the camera. There's probably a more efficient way to do this, but this was the easy way to code it.

Here's my actual code:

code:
#pragma strict
@script RequireComponent(Camera)

var layers : LayerMask;

private var myTrans : Transform;
private var myCam : Camera;

private var mobile : boolean;

private var mousePrev : Vector2;
private var newDrag : boolean;
private var TID : int;

function Awake () {
	mobile = (Application.platform == RuntimePlatform.Android);
	myTrans = transform;
	myCam = GetComponent(Camera);
}

function FixedUpdate () {
	if (mobile) {
	
		// Check touchscreen input.
		if (Input.touchCount > 0) {
			if (newDrag) {
				newDrag = false;
				TID = Input.GetTouch(0).fingerId;
			} else {
				if (TID == Input.GetTouch(0).fingerId) {
					MouseMove(Input.GetTouch(0).position, mousePrev);
				} else {
					TID = Input.GetTouch(0).fingerId;
				}
			}
			mousePrev = Input.GetTouch(0).position;
		} else {
			newDrag = true;
		}

	} else {
	
		// Check mouse input.
		if (Input.GetMouseButton(0)) {
			if (newDrag) {
				newDrag = false;
			} else {
				MouseMove(Input.mousePosition, mousePrev);
			}
			mousePrev = Input.mousePosition;
		} else {
			newDrag = true;
		}
		
	}
}

function MouseMove (newPos : Vector2, oldPos : Vector2) {
	var oldHit : RaycastHit;
	Physics.Raycast(myCam.ScreenPointToRay(oldPos), oldHit, 1000, layers);
	var oldPosition : Vector3 = oldHit.point;
	
	var newHit : RaycastHit;
	Physics.Raycast(myCam.ScreenPointToRay(newPos), newHit, 1000, layers);
	var newPosition : Vector3 = newHit.point;
	
	var deltaPosition = newPosition-oldPosition;
	myTrans.Translate(-deltaPosition, Space.World);
}

FuzzySlippers
Feb 6, 2009

Nothing looks weird about your code (Disclaimer: I don't use US or much mobile) so I would do standard debug stuff: try the touch events in a simpler scene, try it on a different device, etc.

Anyone seen this article on gamasutra about memory management in Unity? Any more expert opinion about how valid it is?

In particular, what's so bad about LINQ? I use it all the time in my UI code and so far I haven't seen any performance problems though I certainly don't do anything in an update loop like his example.

Paniolo
Oct 9, 2007

Heads will roll.

FuzzySlippers posted:

In particular, what's so bad about LINQ? I use it all the time in my UI code and so far I haven't seen any performance problems though I certainly don't do anything in an update loop like his example.

The article explains exactly what the issue is (LINQ is based on closures which require heap allocations in C#). If you haven't seen perf issues then you're just not doing anything complex enough to care, so you can safely ignore it until you can't any more.

Adbot
ADBOT LOVES YOU

FuzzySlippers
Feb 6, 2009

I'm dodgy on this topic so bear with me.

quote:

LINQ has to create intermediary arrays to arrive at the final result, and doesn't have a system in place for recycling them afterwards
He's saying that it doesn't reuse arrays for subsequent queries not that it just keeps gobbling up memory for every query never releasing it right? Isn't that just why it would be silly to have a linq query in an update loop, but if you used linq to periodically adjust a list or something is that so problematic?

I pool all my objects, but I would have assumed the hundreds of megs of graphics getting thrown around would always be the performance bottleneck rather than worry about thousands of KB for delegates or such (outside of some particularly egregious runaway allocation in your game loop). I'm a noob with no c++ experience so I don't have any background in memory management.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply