I have an object - just cylinder (looks like chip) and I want to add to this object like Flip animation. When chip is flip - chip will go up and rotate in the air. Now I want to give a dynamic parameter determines Height for go up.
So right now I know 2 ways:
1) Is just in c# code write object.Rotate() with parameters
2) Write animation clip - and call in C# for Play - but here -I can't pass parameters (right or not?)
So please guys - just give me direction (links) for good Get started with unity3d. Sorry for my English - it's very bad I know ((
The best way to do it purely by script is definitely by using tweeners, I would suggest using this tool : https://www.assetstore.unity3d.com/en/#!/content/27676
Now after downloading this asset to your Unity just create a new script and include the asset
using DG.Tweening;
And here is simple method for doing the actual jump with dynamic parameters.
public Transform chip;
void JumpWithRotation(float heightOfJump, float timeForJump){
DOTween.Init(false, true, LogBehaviour.ErrorsOnly);
chip.DORotate (new Vector3 (0, 180f, 0), timeForJump).SetEase (Ease.InOutSine);
chip.DOMove (new Vector3 (0, heightOfJump, 0), timeForJump).SetEase (Ease.InOutSine);
}
The best thing about tweeners is that you can easily implement easing methods (making transition between two values (linear, sine, exponentional...)).
You can pass parameters to Animation - because animation is just file(it's not a code). So sure - if you want to pass dynamic parameters - you have only one options - by scripts. Just write 1 method who take GameObject and parameters for rotation and its done! good luck
Related
I have the Player move around and when he enters a new Room (via Instancing) his Sprite shows him facing in the Default direction (in my Case down). So If you enter a Room from any other direction then it looks weird, cause for a short Moment you can see the Player facing down even if you came from the right. How can I tell Godot to set the Player Sprite to a specific Frame in Code, so I can set it to the proper Frame for each Direction. I'm new to Godot and I used HeartBeast Action RPG Tutorial for my Movement. So it's using an AnimationTree and AnimationPlayer. I tried "set_frame" but Godot just says it doesn't know the Method.
If you are following the tutorial series I think you are following (Godot Action RPG)… You are using an AnimationTree with AnimationNodeBlendSpace2D (BlendSpace2D).
The BlendSpace2D picks an animation based on an input vector "blend_position". This way you can use BlendSpace2D to pick an animation based on the direction of motion or the direction the player character is looking at. For example, you can "idle_up", "idle_down", "idle_left", and "idle_right" animations, and use BlendSpace2D to pick one in runtime based on a direction vector.
Thus, you need to set the "blend_position" of the BlendSpace2D like this:
animationTree.set("parameters/NameOfTheBlendSpàce2D/blend_position", vector)
Where:
animationTree is a variable set to the AnimationTree.
"NameOfTheBlendSpàce2D" is the name of the BlendSpace2D you want to set (e.g. "Idle").
vector is a Vector2D with the direction you want (e.g. Vector2.UP).
This is shown in the episode 6 of the tutorial series (Animation in all directions with an AnimationTree).
You can find a reference project by HeartBeast at arpg-reference, where you can find a function update_animation_blend_positions that looks like this:
func update_animation_blend_positions():
animationTree.set("parameters/Idle/blend_position", input_vector)
animationTree.set("parameters/Run/blend_position", input_vector)
animationTree.set("parameters/Attack/blend_position", input_vector)
animationTree.set("parameters/Roll/blend_position", input_vector)
Here "Idle", "Run", "Attack", and "Roll" are BlendSpace2D, each configured with animations for the corresponding actions, and this function updates them in sync so that they are picking the correct animation.
As far as I can tell the code from the repository is further refactored from what is show in the tutorial series. This code from the repository is under MIT licence.
I'm trying to make a pleasing "spring" effect to scale a button and other components. In particular I want to scale them in when the view is created and shown, and I want to scale them down when a user taps a button, and if the user releases the button, I want them to scale back up to normal size with the spring effect.
The Facebook library "rebound" is a perfect example, see their demo here: https://facebook.github.io/rebound/.
I tried all the built in curves like bounceIn/Out and elasticIn/Out but they weren't springy enough (elastic is kind of springy).
Any help greatly appreciated!
As #Remi said, you can use the Curve class and override the transform method.
The difficult part is then figuring out the formula to use. I'd play around with something like this curve calculator to get a formula.
i.e. -(e^(-x/a) * cos(xw)) + 1 with a = 0.15 and w = 19.4.
Another alternative is to use existing curves together - since they all start at 0 and end at 1, you can simply multiply two different curves together in your overloaded curve method.
I'd take a look at the implementation of ElasticIn and ElasticOut to figure out how they did the math, but the dart math library should have everything you need.
You can create your own Curve by overriding transform.
As long a mycurve.transform(0) == 0 and mycurve.transform(1) == 1 you can do pretty much anything.
Better late than never:
you may find the package https://pub.dev/packages/sprung useful.
I am trying to make an animation that will fill a tube with liquid and then start moving the liquid inside. I am using an SVG with 3 main paths, the first one is liquid with short height, which then I morph to become the liquid with long height, then I want to "repeat" the morph between the other 2 paths to make it look like the liquid is moving, however when i move from one path to the other using morphSVG, I can't go back to the previous path, so my other morphSVG statement isn't executed.
Here's link to my code:
https://codepen.io/BrittanyR/pen/rJvOyX
As can be seen, I am able to move from one path to the other using:
TweenMax.to("#redSecondary", 2, {morphSVG: "#redPrimary", delay: 2})
But I can't then use this: TweenMax.to("#redPrimary", 2, {morphSVG: "#redSecondary"})
Any idea will be helpful.
Thanks.
It seems like it was just a logic issue in your code - your setTimeout() was alternating between animating #redPrimary and #redSecondary (targets), but you never changed what they were animating TO. So it worked the first time...and that's it. Every subsequent call was just duplicating the exact same movement (tweening to the current values...thus no motion).
I wonder if this is what you were looking for: https://codepen.io/GreenSock/pen/gvzMLG?editors=0010
Note: as a convenience, MorphSVGPlugin automatically records the original path data for the element so that if you ever want to animate back to it (like to("#redPrimary", 2, {morphSVG:"#redPrimary"}), it knows to grab that. It's all automatic :)
So if you want to repeatedly bounce between those morphs, a simple TimelineMax is probably the easiest way. Get rid of all that setTimeout() stuff and just do this:
var tl = new TimelineMax({repeat:-1, delay:2});
tl.to("#redPrimary", 2, {morphSVG:"#redSecondary", ease:Power1.easeInOut})
.to("#redPrimary", 2, {morphSVG:"#redPrimary", ease:Power1.easeInOut});
Does that help? I'm not entirely sure that I understood your goal properly with the animation, but hopefully this nudges you in the right direction.
Happy tweening!
I am trying to figure out how to use correctly body.applytorque(float torque, boolean wake) method on a body with a center of mass, to accelerate it's angular velocity. I want to apply an angular acceleration, in degrees per square second.
According to the libGDX doc, torque parameter uses Newton-meters. To set it, i'll use the formula :
𝛕 = I α
where 𝛕:torque[N-m], I:mass moment of inertia, α:acceleration
on the body :
// java
float acceleration = 120f; // deg/s²
float inertia = body.getInertia();
body.applyTorque(inertia * (float)Math.toRadians(acceleration), true);
but this leads to wrong acceleration, same thing with the mass.
What is the proper use of that method, in deg/s²?
Resolution : the problem came from the world editor UI i was using -
Overlap2D.
How to correct : multiply the torque by 2 in applytorque(...) .
The method i mentionned was used correctly in my example above, and so was the formula.
With Overlap2D software, I'm able to place all the bodies i want into a scene. When I then load the bodies and assets in my program, i load directly the world with. I use some convenience classes provided by ashley, e.g IteratingSystem, to compute directly every entity's behaviour at each rendering. This processing is affecting the forces, or at least torques. However i had no problems with angular impulses.
Thank to David Jeske and Louis Langholtz for having guided me.
I am trying to create a protractor in windows phone 7 using silverlight framework and I am stuck in getting the protractor needle to rotate.
I am using rotate transform and specifying the angle value to the transform name in the code behind.
I need a perfect angle calculation and currently the protractor needle is not rotating as required.
Any help would be truly appreciated, thanks.
try this:
var rotateTransform = (RotateTransform)yourControl.RenderTransform;
rotateTransform.Angle = 90.0f;
I wrote this out of top of my head, but this is general rule how you should do this in code behind... the other thing is - make sure you are getting some values via Debug.WriteLine() and then watch Output in VS.