I've created an animation for a Panel element in Unity. After that, I've moved the element from its original position.
Furthermore, this element is anchored to the bottom of the screen in order to stay there whichever the screen size is.
The problem is that the moment I hit Play to debug, my element suddenly moves to another position, which I believe is the original position where it was when I created the animation.
I may be able to create the animation again. However, this would not solve the problem since a different screen resolution would make a slight change to the position, and therefore the desired position for the element to be would be changed again because of the animation.
Can't I create an animation independent from position? In positive case, how? In negative case, how could I address this problem?
What you have to do is to make animation relative to a parent object. Put Animator on the Panel's parent, animate its child transform and voila - animation is now always played relative to the Panel's parent position.
https://www.highwaynorth.com/blogs/bryan/relative-position-animation-in-unity
Related
I have a badge animation that has a child of text and then a button that decreases the level that should always appear behind the score badge.
I have tried a lot of things(like sorting layer component but then the badge renders over all UI elements even its child text) but fundamentally I changed the Decrease level and Text to just be Default for the layer option and set the Z position and scale to 0. I have then changed the Score Badge and its child to be layer UI and negative coordinates so they appear in front of the camera but the issue still persists.
Here is the editor hierarchy
The issue I am having is the rendering looks like this:
If you use Layers try dragging it in sorting layers the one in the bottom of the stack will render in front.
I have an image in one page of the PageView. I want to animate this image to the next page when i go to it, sort of like when you use Hero animations in navigator page transitions. Any ideas how this can be achieved?
In order to achieve an animation similar to the hero animation. Basically what we will implement is this, you will need 5 elements:
The initial global coordinates
The final coordinates
Initial widget size
Final widget size
The widget you want to animate
Now in order to create this animation that spans the 2 screens we will need to use the overlay that is present in flutter. link
Add to the Overlay the widget that is to be animated (Not the widget present on the screen, a new instance).
Position this overlay entry to be in the starting coordinate of the animation (The original widget's position).
Hide the original widget.
Create an animation that changes the x and y coordinates to the create the custom motion, this can be any curve, the simplest being a simple tween between the starting coordinate and the end coordinate.
Another animation that animates size change between the start and end size. This animation can be combined with the previous one. (One tween animation but the values are calculated manually)
After the animation is done, remove the overlay entry, and show the new widget. (This can be done as a timed operation or as a call back operation)
This is the most flexible between all of the available options since you have access to the widget in all of its states. However you must be very careful when using this method as it might cause a slowdown if not properly implemented.
This packages does what you want https://pub.dev/packages/coast
It is essentially taking the same approach as Flutter’s Hero and HeroController: Detect when a transition is started, search through the element trees of the source and target pages for the widgets marked for animation (heroes, crabs), pair them up based on their tags, and finally create an entry in an Overlay whose position and size is the interpolation between those on the source and target pages.
I know how to make a moving animation of an UI object, but how to make it supporting different aspect ratio screens?
For example, I have an UI object_1 in the left-lower corner and object_2 in the right-upper corner, both adjusted its position relative to the screen's corners. I want to make an UI image moving from object_1 to object_2.
The problem is that object_1 and object_2 are at different positions (even different ratio according to screen ratio) in different resolutions. Then how can I make the moving animation supporting different resolutions?
Thanks for any advice!
Screenshots:
1 Moving starting point where the left-lower checkbox is on 18:9 screen.
2 Moving ending point where the left-lower checkbox is on 18:9 screen.
3 Moving starting point, changed to 16:9 screen, and the screenshot shows that the position of the finger image does not match where the checkbox is.
4 Moving ending point on 16:9 screen, same problem with the above one.
OK, problem solved. It turns out the animation supports changing anchors at certain frames. So just turn on recording and adjust whatever you like.
In my project, first frame I set the finger image's anchor to the middle-lower point then record its position; when starts the moving animation, changes its anchor to middle-upper point then set the destination position. If the screen aspect ratio changes, since the animation also uses the right anchor data with the two check boxes, they'll match perfectly.
FYI, here's a screenshot of the animation window to help you understand.
This may help,
docs Unity3d site
This will support animations.
I'm trying to add some buttons to a gameObject which is a scroll view child. The child is a very wide image, about 4 times as wide as normal screens, which is why I let it control the height, so that it is always from top to bottom, and only exeeds horizontally where scroll is allowed.
Here you can see my setting.
1. is the wide image
2. is a banner that used to be part of the image, but now I want it to be a individual gameObject.
I don't know how I can make the banner (2) inherit the behavior of the "full map" (1), right now when I choose free aspect and resized the game view, the "full map" scales nicely, so the it always fits from top to bottem. The more narrow the screen is, then more of the map will exceed to the right, and vice versa.
However the problem is that then banner (2) has a rect transform, which is set with x,y coordinates relative to the parent which scales. So as i resize around the view, the banner gets out of it's intended position, and also does not scale with the. I have tried many different components, but without luck. Here among, scale constraint, canvas scaler, position constraint
As you can see in this gif, the banner does not scale down, as the island gets smaller, also it stays in the same position horizontally.
Any suggestions on how I can make the children os the map behave as they were part of the map?
Deleted previous, misunderstood the question.
Proposed solution:
You remove the map part from UI and create it as an object: You attach the map image as a texture to (ie) a plane (see a video here). You add the "infinity island" as another texture and have it placed over the island image.
After that, you control the camera to zoom in/out of the island and not struggle with any scaling or moving UI.
I think you need to anchor the images to center of the island mini image, you can drag the anchor gizmo from the scene hierarchy.
If you see it as free aspect it gets buggy and difficult to handle, but if you choose a resolution everything is smooth.
Is this what you want?
Change the resolultion
Or does it just change where it's rendered? I have performed this transform and I think the object's frame's origin's y position stays the same.
I think what happens is that it just renders the frame in a different position. That's why the position values don't change.
Also, to have something occur after the animation, I will use a timer to run a piece of code after the animation.