Unity - How to disable animation interpolation / animation curves? - unity3d

I'm trying to animate a hierarchy of 2D sprites (essentially body parts) by explicitly setting sprite positions at various key frames throughout a given animation clip. Unfortunately, Unity is implicitly changing all of the sprite positions using interpolation between key frames. This causes the sprites to look like they're sliding around rather than immediately transitioning into their correct positions.
So far I've come up with 2 rather poor solutions:
I could potentially create separate animation clips for each combination of sprite positions and transition
between them using mecanim parameters or in
code, but this seems tedious at best and inefficient at worst.
I could add more keyframes (either in the animator tab or in the
curves screen) that maintain each sprite position until just before
they need to be updated. This is a slightly better option but also
extremely tedious.
Is there any way to tell Unity to disable animation interpolation at least as far as positions are concerned? Thanks.

In the current version of Unity (2019.3), go to curves view, right click a keyframe node and select Left Tangent -> Constant. You may want to use Right Tangent depending on the use case. That should give you the instant change you're looking for.

Have you checked Brackeys video of animating 2D in Unity? Maybe it can help you :)
The following link is his video on how to animate 2D sprites.
https://www.youtube.com/watch?v=whzomFgjT50

Alright, I've come to the unfortunate conclusion that Unity forces you to use curves when dealing with animation keyframes and that you need to add an extra set of keyframes for abrupt shifts in animation.

Related

Is it possible to animate anything with natural way in Unity or smt else?

I m wondering that if is it possible to animate anything along the rules of physics.
I mean, i have a cube, and two legs attached to that cube. I want to just animate that legs one after each other, but unity or other software will force its animation system to behave to my animated legs to make my cube walk. I wont change positions for my body(cube) but legs will do that.
demonstration:
https://streamable.com/dda610
Yes, this animation type is called procedural animation. You base your animations dynamically based on physics.
https://en.wikipedia.org/wiki/Procedural_animation
good video:
https://www.youtube.com/watch?v=LNidsMesxSE
tutorial:
https://www.youtube.com/watch?v=9Wh6fzSl_u8
Physically based animation is a complex task. You can use the timeline to animate legs but they won't work too well physically. You probably want to use code to keep the body a fixed height above the surface and use the timeline editor to animate the legs. Or perhaps keep the body at the same height and use 'inverse kinematics' to move the legs in a more realistic fashion. Neither of these options will be very quick for you to start using really effectively if you have very little experience with unity or with code but knowing what to look up is half the battle of learning.

Mixamo upper body rotation only not working

This is my first question on Stack Overflow so I apologise if anything is not to standard.
So I'm a beginner in Unity exploring into intermediate territory.
I am learning Unity by doing a third person shooter but throwing items instead of a gun.
I found the perfect animation pack from mixamo called pro magic pack, which is basically a wizard with casting animations etc.
I have setup the camera, controller etc and I'm working on the animations, to which I have all the jump animations, walk blend tree etc all within MECANIM.
My problem is that I have another layer specifically for upper body movements only so he can run/walk whilst performing an upper body magic casting animation, I have setup the avatar mask for the upper body which works fine, but due to the nature of the animation the upper body rotates as he performs the animation, but this rotation doesn't rotate around the hips he just flails his arms in the current direction the chest is facing.
Is there anything I can do without going down the coding IK's route, or excessive coding (will do this if it's essential)? P.s. I've also tried various checks and unchecks of bake into pose (to which I'm still grasping the understanding of).
Thank you in advance for your help, I've attached some GIF's to understand my issue.
This is the animation I want but only the upper body:
Upper Body Animation I want
This is what I currently have:
Animation I currently have
It seems like the upper body isn't properly rotating and the spine or hips?
Upper Body avatar mask
EDIT: With thanks to Vasmos for pointing me in the right direction, I have found that enabling not just the upper body on the avatar mask but ALSO enabling the ground as seen here: Upper Avatar Mask
I've added this GIF as the current situation, it looks okay and works almost as I want it to, I just need to figure out how to stop the legs rotating with the base: Correct Direction but body rotating with animation
EDIT 2: After research and help from vasmos, the solution I found to this is to enable the Foot IK option of the animation as seen here: Solution to animation affecting rotation
In the throwing animation the movement begins in the root hips bone, it looks like in your mask you just put the upper body when you still need to include the root hip node. It seems like you are on the right path with layers and mask to blend the two animations just keep playing around with it, just incase you don’t have it : https://docs.unity3d.com/Manual/AnimationLayers.html?_ga=2.241528322.1842043308.1588381034-1055993846.1587850410
edit: yeah you are close maybe just remove the hip from the upper body mask and start at the next node up(spine?) and keep moving up one node at a time until you get desired effect

How to make dotted physics shooter simulator like bubble shooter

I would like to achieve something like this:
I've already done something similar using the Unity particle system. It works fine but the problem is when you rotate the pointer, a wave is formed. Is there any other way?
If you want to avoid the wave using particle effects, you will need to move each particle immediately by how much it needs to move to get into its new position. The reason you get a wave now is because you're only changing the emitter's direction.
Instead, it might be a better approach to use a wrapped LineRenderer and scrolling the UVs on the texture/renderer on each Update using lineRenderer.material.SetTextureOffset. You'll also need to calculate the points to draw the line, and set those as appropriate in Update as well.
This way, when you change the aim, the LineRenderer's positions can all move accordingly and the dots will always appear to be in a series of straight lines.
Increase the speed of the Simulation Speed in the main (top) section of the Particle Settings. Try 10, to start with. You might need even higher. Default is 1.

Normalize Vector3.Distance based on rotation

I am trying to measure distance between multiple positions but I do not want the rotation to affect the distance. In concept, I want to track the starting transform and upon each update track the distance traveled without regard to the change in rotation. I am using an HTC Vive controller and people tend to rotate their hands and I want to control for this.
I've tried resetting the Eular Angles, but this doesn't seem to work.
Adding an Analogy that will certainly help.
Think of it like trying to draw and measure a line with a pencil, the position is in the eraser, and I can hold the pencil in any number of ways and in fact change the position in the middle of drawing the line, but my line will remain straight and the measurement will remain accurate.
Any help is appreciated.
I believe your problem lies around the position you are tracking. It sounds like you are tracking the transform.position of one of the child elements of the Vive controller model, leading to the situation that you're describing with the pencil eraser analogy.
Depending on where your script is attached, you could either move this to the top level element of the Vive controller, or alter your script to instead track transform.parent.position, which shouldn't be affected by the rotations of someone's hand.

Cocos2d - Creating collidable Sprites?

Hello everyone I an very new to cocos2d, so I apologize if this is a simple question. I would like to create to sprites that collide when they hit each other.
For instance, one sprite, spriteA, is in a fixed position on the screen. And another sprite, spriteB, is moving around the screen. SpriteB will collide with spriteA. If that doesn't make sense or you don't understand it, tell me and I will elaborate further. Any help is appreciated. Thank YOU!
Try using Chipmunk or Box2d physics systems. These are included with Cocos2d and work by having a physics simulation that updates with every time the graphics change on screen.
The physics simulation will tell you if two objects are overlapping, and will provide physical attributes like weight, slipperiness (friction), speed and direction, which creates reactions like bouncing, sliding, realistic loss of speed and changes of direction on impact.
If you are new to physics simulation, here's a 30 second run down:
Create "bodies" in the physics simulation that represent each graphical sprite
Bodies are usually defined more simply than their graphical counterparts, like a circle, square or simple polygon shape
In order to update the graphics on the screen accurately, first you establish a pixels to meters ratio. Meters are notional (i.e. made up) measurement that is used in the physics sim
Each time the physics simulation "ticks", you update the graphics on screen accordingly
So if a body in the physics sim moves 1 meter, you might transform the pixel sprite 32 pixels
Here's a good tute on collision detection using Box2d.
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
enjoy
Its actually very simple:
Just schedule a timer: [self schedule:#selector(checkForCollision:)];
Specify the method: - (void)checkForCollision:(ccTime)dt {}
In the curly braces, make CGRects for each sprite using CGRectMake.
Then in the same method, just call: if (CGRectIntersectsRect) {}
That easy!
Well technically speaking when the 2 sprites interact, or share at least one common point, then they are colliding. I'm a little confused by your question. Are you asking for direction on how to make the sprite move on screen, or are you asking how to handle the actual collision(such as calling a method if they collide)?