how to play two animations in the same time in unity 3D - animation

I'm trying to rotate the Earth around the Sun in Unity 3D..
my question: How to rotates the earth around itself and in the same time it rotates around the sun. I can't do more than one animation for one object in Unity3D?
please,help me.. :)

I will do something like this :
public float speed = 1;
void Update() {
// Slowly rotate the object around its X axis at 1 degree/second.
transform.Rotate(speed * Time.deltaTime, 0, 0);
// ... at the same time as spinning it relative to the Sun
transform.RotateAroud(sun.transform, Vector3.up, speed * Time.deltaTime)
}
from http://unity3d.com/support/documentation/ScriptReference/Transform.RotateAround.html

There are several options in Unity3D to do this like blending, layering, adding and fading. Have a look at Unity - Character Animation and Unity - Animation Scripting

You can play two animations at the same time by creating multiple layers directly inside the unity animator system.Here a useful step by step guide:
http://gamedevelopertips.com/unity-run-2-animations/

Related

Unity 3D - Dynamically 'slicing' background image

I'm fairly new to Unity and not quite sure how to handle this problem.
I have two images, one has clouds on it (day) and one has stars on it (night). What I want to do is show the clouds in the top of my scene and the stars on the bottom. There is a ground object in the middle of the screen where the player will be walking on, this should be the dividing line between the two images. The ground however is not one straight line but can have height differences.
The "solution" I came up with is to use the ground object(s) to slice the images so it kinda serves as a dividing line. But not sure if this is even possible. Maybe I could do something with 2 different camera's or mask the images somehow.. (Just throwing my own thoughts in here as well) I'll be fumbling around with these things in between and try to keep the topic up to date with what I tried.
I put in an attachment to (hopefully) make it more clear.
Greets,
Lukie
attachment: https://imgur.com/a/lblJXPi
The first solution to my mind was preparing a tileset. If you're not going to design a different section every time. So if you're not going to do a computer design. You can do it yourself by adjusting the size.
You can also dynamically generate the stars with the -y axis of the ground object and the clouds with the + y-axis. You can use instantiate function
Example:
public GameObject clouds;
public GameObject stars;
// Start is called before the first frame update
private void Awake()
{
Instantiate(clouds, new Vector3(this.transform.position.x, this.transform.position.y + 3.625f, this.transform.position.z), Quaternion.identity);
Instantiate(stars, new Vector3(this.transform.position.x, this.transform.position.y - 3.625f, this.transform.position.z), Quaternion.identity);
}
Of course, the background design that you will use here must be sustainable.
Dynamic Background

React Native: Continue animation with last velocity of touch gesture

In my React Native application I have some tiles (wrapped in a View for the example) which are half of the full width wide. They act as buttons and slide to the opposite side to open a menu. When I perform a swipe gesture and release the finger before the slide reaches its final position, I want the slide to animate to its final 'opened' position. The animation should start with the last velocity of the touch gesture for a smooth impression.
I implemented different variations but did not find a good solution (You can find my test-component in my GitHub repository). My View has a PanResponder to manage the gesture and to get the velocity. I started to use the Animated library, but the provided methods do not solve my problem. The only method where I can pass a initial velocity for the animation is the decay, but I can't pass a parameter where the animation should stop. With a timing animation I can set a final value, but can not pass a initial velocity (so the animation starts with a velocity of 0 which looks very jumpy). I tried to combine these two methods, but that does not work properly.
On iOS I could use a horizontal ScrollView with pagingEnabled, which shows the desired effect - but then I do not have the feature on Android.
Any ideas how I can solve this problem and show a smooth animation, starting with an initial velocity and ending on a given position, after the touch gestures end?
Thanks for your help!
EDIT I added the link to my last test component...
You can get a close approximation of the velocity by setting the duration of the timing animation
const duration = Math.abs((this.props.MAXDISTANCE - Math.abs(distanceMoved)) / velocity);
MAXDISTANCE is your final position
distanceMoved is the current position (gestureState.dx)
velocity is the current velocity (gestureState.vx)
You can use Animated.decay or Animated.spring to achieve this effect.

Unity 3D : UI Image in the direction of a game object

I'll explain my issue (My English is a little lame sorry).
I have a Player ( Camera) who is able to move in a Unity Scene. In this scene there is some GameObjects. Those GameObjects May be too far for the camera to see. What I want to achieve is to have an UI Image that appear in the direction of every objects. Even if the objects are too far.
Example : The player stand at a position. In front of him there is an object that is far. I want to have a GUI on screen who says "there is an object at 200 m ". If there is an object behind him I dont want anything to appear. But if he turns back, it will appear cause the player is in the direction of the said GameObject.
I really hope I made myself clear. Please tell me if you need any further explanations. Thank You community !
Answering to an old question of myself :
Here's what I did :
if (markIsOp) //Check if it's worth calculating
{
//Calculs the Viewport Position of the object
Vector3 ViewportPosition = Camera.main.WorldToViewportPoint (transform.position);
//Calculs it's Unity Canvas position (O.5f because UI anchor is middle)
Vector2 WorldObject_ScreenPosition = new Vector2 (
((ViewportPosition.x * mainCanvasRect.sizeDelta.x) - (mainCanvasRect.sizeDelta.x * 0.5f)),
((ViewportPosition.y * mainCanvasRect.sizeDelta.y) - (mainCanvasRect.sizeDelta.y * 0.5f)));
//Making sure it's forward (markRect is my UI Element's RectTransform)
if (ViewportPosition.z > 0)
markRect.anchoredPosition = WorldObject_ScreenPosition;
}
Thank you for your responses.
Have a nice one
You could as well use Camera.WorldToScreenPoint to calculate the "UI-Position" of your GameObjects and then calculate the distance using z-Coordinates of Gameobjects and Camera.
Use a raycast from the player to the game object, and calculate the difference.

Scrolling texture on quad is laggy

What could be the reason of lag while I scroll a simple texture on a quad using Unity 4? The lag is not consistent, the scroll works for like 3 or 4 seconds smooth and than comes the lag and so on.
Here is the code
public float speed = 0.01f;
manager.scroll_speed = Mathf.Repeat(Time.time *speed, 1);
renderer.sharedMaterial.SetTextureOffset("_MainTex", new Vector2(manager.scroll_speed, 0));
What should I do to get rid of the lag?
Modifying sharedMaterial will change the appearance of all objects using this material, and change material settings that are stored in the project too. I'm guessing you wanted to do this on purpose but maybe scrolling textures on a whole bunch of objects is just not efficient. If it's just one object then just use renderer.material. Actually try using renderer.material anyway and just having different instances of the script

Orbit Controls zoom issue

I am trying to get infinite zoom functionality,
While looking at the following three.js example:
http://threejs.org/examples/misc_controls_orbit.html
While getting closer to the target vector, the zoom factor reduced and reduced until it barely worked, for an end user it looks like it is stuck. panning won't really work, and in order to zoom out user needs to use the mouse wheel for like ages.
Is there a way to get infinite zoom functionality?
Thanks.
as mentioned it is zooming infinitely ( but it's zooming infinitely to the target at the center of the scene so it will never pass the target and thus never zoom beyond the center of the scene ), there's a couple changes you can make to the controls object in order to render the desired effect ( if I'm understanding you correctly ).
one small change you can make is change the target location from the center of the scene to the other end of the scene, given the the camera's far perameter is set to 1000 we can try setting the target's z position to -1000 in your init() function like so:
controls.target = new THREE.Vector3(0,0,-1000);
here's a working fiddle: http://jsfiddle.net/6gn7k0m4/
in that example you'll zoom past the scene and slow down when you get to -1000. Another approach might be to change the dollyIn and dollyOut methods so that rather than getting infinitely closer to the target what it does is change the camera's z index, this way when you zoom past the target the camera will still rotate around the center, you can do something like this
controls.dollyOut = function(){
this.object.position.z -= 100;
}
controls.dollyIn = function(){
this.object.position.z += 100;
}
here's a working fiddle for that example: http://jsfiddle.net/6gn7k0m4/1/

Resources