I have a unity state machine with four states: idle left, idle up, idle down and idle right.
To transition between these states I had to create 12 transitions. (the white arrows). This already seems unwieldy, but now I need to add 4 more states: running up, running down, running left and running right.
Does that mean I end up with 8 states and 24 transitions running between all of them? That seems very unwieldy to me. What if you need to change something later?
I know I can transition by code, but that doesn't seem to be the recommended way of working.
animaor.Play("runningright");
What would be the recommended way to work with lots of states?
As #Uri Popov said, you should consider using "Blend Trees". They are there for the same purpose. The help blend between multiple similar animations. for example, walk and run animation are similar in a way that they depend on character's movement speed.
Look at the following links to learn more about blend trees. These are only basic but will surely help you with your problem.
Unity - Manual: Blend Trees
Blend Trees - Unity Official Tutorials
When to use a blend tree vs state machine for animations (just another question on gamedev.stackexchange)
Related
I'm currently just trying to learn to use the animator within Unity, I'm very in-exp at animation and don't understand it even in the editor as I focus on programming/scripting.
I have an animation and the states for the animations as-well as the conditions all working perfectly however the animation check for the next state is way to slow. I've tried changing the speed of the actual state but it speeds the animation up and makes it look like my character is walking insanely fast.
I've tried messing around with the frames, making them over a longer time period and making the speed of the state faster however it seems to counter act each other, when I make it longer frames the pace of the animation is slow and then when I make the speed of the state go quicker it just makes the frames tick faster making the animation faster.
What I believe is happening is that the check for the next state of animation is happening once the full animation has been played. However what I need is the check to be happening constantly (as if frame by frame of the unity game not the animation).
Any advice would be great, I've tried using youtube to solve this before coming here however most people are creating a platformer game where as I'm trying to aim for a top down 2d, all directional character movement instead of the linear x axis character movement., and outside libraries.
I deeply apologise for my inability to find a suitable source. I have literally just came across an article online that came across a simple solution.
here:https://answers.unity.com/questions/221601/slow-animation-response.html
basically if you can't be bothered to click the link and you are having the same problem,
find exit-time by clicking the transition and then in the inspector and untick it.
Sorry.
This is posted here since this is Xbox specific, but I am also posting this onto the Unity forums.
When testing my Unity game on Xbox One I am getting a very large amount of visual "jitter" from the ball. This is a skeeball game where you control the movement of the ball. Essentially the core of the movement is similar to the Rollerball tutorials. On PC this works fine and there are no perceptible jitters. However, on Xbox, I am seeing this a lot more. The object is travelling large distances with the camera following smoothly behind. None of the other objects or scenery are affected, I actually think the camera itself is moving perfectly. But, the ball itself seems to glitch.
Changing my camera movement to LateUpdate seemed to minimize it the most on the PC, but that doesn't make sense to me since I am still not convinced the camera is the problem.
Any help would be greatly appreciated. Perhaps a quality setting isn't placing nice with the Xbox?
Thanks!
Nick
Keep in mind the clock speed of the CPU on the Xbox is likely much slower than your PC (although there are more cores).
Unity is primarily single threaded, so that could explain the performance difference. Here are some things you can try:
* Make sure you are running the "Master" build on Xbox. The default is "Debug" which is significantly slower.
* It's possible it's something with the physics.
Once you've checked to make sure you aren't running Debug, the next step would be to use the Unity profiler to see where your frame time is being spent, then depending on what the cause is optimize that part.
Here is more information on the system resources:
https://learn.microsoft.com/en-us/windows/uwp/xbox-apps/system-resource-allocation
There is also a great post about the graphics debugger here:
https://tarhik.wordpress.com/2017/09/04/antimatter-instance-dev-log-entry-2-using-microsofts-graphic-debugger/
It looks like switching the RigidBody to use "Extrapolate" instead of "Interpolate" fixed the issue I was seeing. I am not sure if this works for every situation, but for the scale of the levels and the player physics of my game this seemed to do the trick.
The player carries the flashlight so it is moving all the time. I'm aware of using a spotlight to make a flashlight when developing for the PC but it doesn't work for android. I have tried searching about it and all i have come across is creating a dynamic material that's applied to a certain area to give the illusion of a flashlight and it doesn't look good at all. So i would like to know if there is any other way to achieve this.
I think one option would be to use post processing. I am not sure is this better than using materials, but it is different (perhaps easier) way.
Here is example that I made quickly (obviously you would need to fine tune it):
fake light GIF
This contains ambient light and post processing effect.
Yellow area in middle that you see as light is not point light, it is just effect.
It is possible to change "light" area/intensity/color/... as well as overall darkness.
Also, worth mentioning, I made this quickly since I had already somewhat similar post processing effect, I just adjusted it so it look like flashlight.
You can find more information here:
Post Process Effects
Post Process Materials
I have finished my game in Unity already.
But whenever I'm trying to build the game, it stops at the point as shown below. Does anyone know the reason why it happens? It always stops at the same point....
It's a problem with baking the lightmaps on your scene.
Unity doesn't like huge objects when it comes to baking lightmaps on them and it can certainly kill the light transport on a build.
You can try to open the Window menu from the main Unity menubar and search for the "Continues baking" checkbox under Lightning and uncheck it.
Or you can just split your bigger objects on your scene which may cause this problem.
Here's a thread detailing the issue a bit.
I've also seen people working around this problem by disabling Global Illumination altogether so that may be a solution for you as well if you are using it and you are willing to give up on that feature.
Edit: Another thread about this sort of thing with a decent solution - not sure why I didn't remember it for first but it's a good idea before trying to split your huge objects to mess with their "Scale In Lightmap" property as well to reduce the lightmaps' size.
You can also try the "Advanced Parameter" options.
Something must wrong here either with me or my monitor or GPU. Others also suffer from this phenomena see the links.
Now I would like to emphasize this problem is exist, being optimist I think there is some solution. Maybe it is only noticeable in special circumstances, and definitely not a performance (or GC) problem. If it would noticeable in all circumstances Unity3D would be useless...
My goal to use this wider forum to specify this problem is my hope the wider community may have wider scope to search the root of the problem. I think it is not algorithm or Time class usage related. Maybe the Time.deltaTime itself has bugs or mislead in some circumstances.
Just a feedback if anyone can reproduce the vibrating effect or not may have diagnostic value. (it seems to be oscillating in horizontal, the left and right edges are very blurry.)
Marrt created a web demo for Unity to demonstrate the effect:
http://marrt.elementfx.com/SmoothMovementTest.html
Whatever I do this demo is so vibrating + choppy. NOTE: All my self created simple scroll projects running in editor or standalone desktop are also exhibits the same, so it is not about 'how to use Time.deltaTime'
I thought the problem is in my hardware until today I saw this WebGL demo (use Chrome):
http://webglsamples.googlecode.com/hg/aquarium/aquarium.html
It is so smooth (any fish movement, also the rotating also the light fades) I mean smoooth. Why I can not produce (no one produce) this with Unity (at least in my machine)?
If anyone interested there is an exact proble description here, but no all answers solve the problem.
The problem in details:
http://answers.unity3d.com/questions/275016/updatefixedupdate-motion-stutter-not-another-novic.html
I tried all the things including the programming variations + quality setting (VSync etc)
My very simple self created projects are running 1000 - 2000 fps and still vibrating + choppy.
I spent 2 days to get the rid of this poor visual experience. Did all the programming thing what mentioned in the linked threads + tried to configure my video card (btw Radeon 6770 with 1Gigs)
Any thoughts?