Unity Animation Cycle Offset not working - animation

The way I understand it, is if I have an animation that's 30 seconds long and is also a loop, through Cycle Offset I can make this animation start at a time different than second 0. So I could make it start at second 10, go to 30, then back to 0, to 30 and keep looping that way. I have a Game Object, an Animation Controller and an Animation Clip. I set a whole bunch of different values for the Cycle Offset of the Animation by selecting it in the Project Folder and then updated its settings in the Inspector and it does nothing, the animation still starts at second 0 every time, regardless of what value I write in.
Not sure if this helps at all, but I also duplicated my Game Object, Animation Controller and Animation Clip so I actually have 2 of each. I did however, go to my Animator window, to make sure the default state for each Animation Controller is different and it is. I also checked that each object has a different Animation Controller. I honestly don't even think this part matters that much, because even if these were wrong, the animation would at least start from a later point on both game objects when changing the Cycle Offset. What happens though, is basically nothing, the animation just starts from second 0, goes to 30 and loops every time.
What am I missing?
Thanks in advance!

Figured out the error. I guess entering the value manually for some reason it wasn't working. What I had to do instead is to first drag my cursor over the text "Cycle Offset" to modify the value that way.

I don't know if it is the same problem but I had a similar one. What I did wrong was I was setting the cycle offset value as frame (if wanted to offset the animation 15 frames I entered 15)
It seems this field must be entered as rate to full cycle. If you want to offset the animation half way you should enter 0.5. This sould offset 15 frames for a 30 frame clip.

Related

Threejs/React-Three-Fiber Animation Reset Thumbnail Keyframe

I am making an animation in react-three-fiber that plays 1 repetition and then resets correctly. However, when it is interrupted midway through, the default/resting/thumbnail keyframe changes to the place where the animation was interrupted. The animation still works, it's just where it resets to that's incorrect. Is there a way to reset this default keyframe to the correct one?
I've found a workaround, but a I hope somebody else has a better answer:
actions['key'].stop().play()
actions['key'].paused = true
Basically, if you play and then pause it immediately, the animation will be on the first frame

CABasicAnimation not updating custom CALayer properties when exporting through AVAssetExportSession

I'm adding a subclassed CALayer onto video, and exporting using AVAssetExportSession, but am stumped on getting CABasicAnimation to work for a custom property. I started out with this approach: Core animation callback for progress
There's a "progress" property, that I scale from 0 to 1 using CABasicAnimation to match the timing of the video. On-screen, in a playerView with an AVSynchronizedLayer, "progress" gets updated, and everything is hunky dory. It works exactly as I'd expect.
On export, however, the CABasicAnimation for the progress parameter does not seem to update. I can set different "from" values for the animation, and the "progress" value is set to that for the first frame that gets rendered -- but never changes after that. I've checked the CALayer, as well as the model and presentation layers, and they all have the initial "from" value, each time a frame gets rendered.
If I attach other CABasicAnimation objects to my layer (e.g. scaling, position), they work as expected.
My overall flow goes a bit like this
AVMutableComposition gets created, with audio and video tracks inserted
Build a layer view hierarchy, attaching CABasicAnimation objects. One animation is for the "progress" parameter, and that's where the trouble is.
AVVideoCompositionCoreAnimationTool is created, to connect the video with the CA layers
AVAssetExportSession generates the video
Parameters related to stock animation key paths seem to be fine. The key path for "progress" does not seem to update. I'm suspecting that AVSynchronizedLayer does something for the on-screen updates, and that's not happening for the session export -- but I'm stumped as to what it is that I need to do.
My CALayer subclass implements needsDisplayForKey, and it does get checked for the "progress" key before the render starts -- so I think that the CABasicAnimation, and the rendering pipeline, are aware that "progress" should change.
+ (BOOL)needsDisplayForKey:(NSString*)key {
if ([key isEqualToString:#"progress"])
return YES;
return [super needsDisplayForKey:key];
}
My working theory is that AVVideoCompositionCoreAnimationTool sees the basic animation for my "progress" key path, sets things to the start value at the beginning of a render, and then does not update as the render goes along. And the reason it doesn't update? Because I'm dense, and have totally missed doing something important.
If there's an example along the lines of adding a time code overlay, that would great to look at. I don't think what I'm doing is that exotic, it works great on-screen, but I'm clearly missing some trick with the video export.
--
An update; still no progress on getting CABasicAnimation to work as expected for custom properties, and when exporting video to a file. There seems to be a lot of layer copying/remapping/etc, happening behind the scenes, and I'm sure I'm doing something wrong.
I've got a work-around now that gets the job done, but is a hack. I create an integer frame count property for the view object, and increment it each time the view gets redrawn. The video export is at 30 frames per second, so all I need to do to find out "when" the frame is, is to divide by the frame rate. As far as I can tell, the individual frames are rendered in a "timing perfect" universe, and then compression gets applied, so the actual playback rate may vary.

Problem when assigning Input.mousePosition to transform.position in Unity2D

I have been following the Inventory tutorials for Unity by Kryzarel and have encountered a weird issue that I think may be from something unrelated.
Tons of googling has yielded no results. It seems like an obscure issue.
https://www.youtube.com/channel/UCOM0GGMEcu-gyf4F1mT7A8Q/videos for reference of the channel.
But the issue I'm running into is I do the following:
draggableItem.transform.position = Input.mousePosition;
So basically draggable Item is a reference to an Image component on a GameObject. I log Input.mousePosition before hand and the values make sense (within the hundreds e.g. (563,262,0)). However, the transform position is nowhere near the number logged. For the example, I'm seeing (48660.31, 23917.95, -7889.887). There is no logic between the debug.log statement giving Input.mousePosition and the code assigning it to the transform. Anyone have any idea what I could possibly have configured wrong, or could be wrong?
I would expect the position to be (563,262,0) not the ridiculous number that it ends up being. I've tried localPosition instead of transform.position, and it sort of works. In that it's off by about 500 or 700 to the top-right of what I'm moving relative to the mouse, I want to avoid hacky solutions like subtracting some magic number if possible.
Edit: Some further background, other mouse clicks and mouse related things appear to work correctly. It's an orthographic camera, or the default for a unity2D project
Solution: IN my case I was able to set it per the accepted answer, I then had to modify position not localPosition and also had to zero out the z-value of the world point.
The mouse position is relative to your screen, not your world. You need to convert the screen space to world space with:
var pos = Camera.ScreenToWorldPoint(Input.mousePosition);

Want to implement delay in scroll to scroll smoothly in Scrolltohorizontal offset method

I need to scroll smoothly when scrolltohorizontal offset value sets. From 1000 offset, if i scroll to 5000, it suddenly moves with a blink and fix the view in 5000. I need to scroll slow and smooth like animation and have to reach the destination. Without using the story board how can I achieve that?
I have found that without implementing the storyboard animation we cant acheive the smooth scroll. I refer this class and got the result.
http://blog.devarchive.net/

Animation On Local Position

I am trying to make this:
The chracter walks up to a large crate, the player presses the e key and an animation starts playing, such that the character climbs up on to the crate. (all in first person view).
So far I tried this with normal "First Person Controller" Prefab in Unity.
My code so far:
function OnTriggerStay(other : Collider){
if(other.tag == "GrabZone"){
if(Input.GetKeyDown("e")){
animation.Play("JumpToLedge");
}
}
}
However when I use this on the FPC, it will always play from the position the animation is created on. I also tried to create an empty game object, placing the FPC in there. Gives same effect.
Most recently, I tried just animating the graphics of the FPC alone. This seems to work, but since the Character Controller itself is not animated, that stays on the ground. So the whole FPC won't work anymore.
Is there anyway I could let this animation play on the local position the player is on at that time? Or can you think of any other logical solution for a grab and climb?
You should always animate from the 0,0 position. This way you can always easilyl determine what to do and where to go with your model.

Resources