How to change key frame values in GDScript (Godot)? - animation

I am trying to play an animation when a scene is instanced. It is a simple animation that translates y from -5 to 5. The animation plays but it plays at x = 0 and z = 0. I understand this is because the translation values for the respective co-ordinates in the animation are set to 0. I have a spatial node on my player scene that can grab transform info and pass it on to my animated scene, but I do not know how to dynamically change the x and z values of the key frames in script.

This answer contains three solutions to the problem...
Target a sub-property
If I understand correctly you want to animate only the y coordinate, and leave the other coordinates unchanged. That is, you don't want to animate the translation vector. You want to animate the y or the translation, a sub-property. This is possible out of the box, but the UI won't offer it to you.
Start by creating a track from the animation editor. You click on "Add Track", select "Property Track", and then on the object you want, and select translation. Now, while the track is empty (no key frame inserted yet), modify the track name to :y at the end.
The track would have been create with a name such as SpatialNodeName:translation, you are going to change it to SpatialNodeName:translation:y.
Afterwards, when you add key frames, they will be for translation.y. Note: doing SpatialNodeName:transform:origin:y or even SpatialNodeName:global_transform:origin:y also works. Similarly, you can imagine how do it for only rotation or scaling, and so on.
Create custom properties and animate them
I'll also mention that another option is using a Tween node (which are easier to create from code).
And also that both Tween and AnimationPlayer can animate any property. Thus, if you need to animate something that is not available, consider adding a property (see setget).
For example:
export var y:float setget set_y, get_y
func set_y(new_value:float) -> void:
transform.origin.y = new_value
func get_y() -> float:
return transform.origin.y
Then you can add a track for the custom property, and animate it like any other.
By the way, also notice the AnimationPlayer can also have "Call Method" tracks.
Modify the animation
Manipulating an animation from code is also possible. I've seen an example elsewhere. You can call get_animation on the AnimationPlayer to get the animation. Then on the returned animation you can call track_get_key_value and track_set_key_value. However, this rarely what you want to do in practice (unless you are making a Godot addon that creates or modifies animations or something like that).

Related

Aframe a-sky change rotation upon scene change

Hi I am trying to navigate between scenes. And when i navigate between scenes, i am not able to set/update rotation of the changed scene. i am storing rotation of scenes and then navigate between. Please help struggling from many days
Link to my code on Glitch https://glitch.com/~thin-newsstand
Working explained.
1. Save camera button saves the rotation into select along with the scene and
custom data attribute name data-r
2. If you inspect select dropdown options, you will notice.
3. When select option is changed, it will change sky image from select option and also change rotation.
4. I have used aframe-viewable-component.js to restrict top/bottom movement of skybox.
It sounds like you want to save and restore camera rotation, when a new panorama is loaded.
Since you are using the look-controls component on the camera, you will need to do this using that component. It might be best to modify that component, and create your own custom variation. You can download the original here:
https://github.com/aframevr/aframe/blob/master/src/components/look-controls.js
The component does have a built in function for saving and restoring position and rotation
saveCameraPose: function ()
restoreCameraPose: function ()
as it is written, the component can only save one entry
this.savedPose.position.copy(el.object3D.position);
this.savedPose.rotation.copy(el.object3D.rotation);
Depending on what you want, you may have to save the position/rotation to new variable that are associated with each pano, so that when a new pano is selected, that same entry for camera pos/rot is also loaded and camera restored. It would probably be best to do this with an array. Psuedo code looks something like:
Make an array (containing objects: {camPos, camRot}). named savedCamPR.
When new pano is selected get the index of current pano. named curPanoID
Save the look-controls pos/rot to savedCamPR[curPanoID], ie the array using the index of current pano.
Get the index of the new pao.
if there is a saved entry in the in savedCamPR, use that to restore the camera.
If you have trouble figuring it out, let us know, and I can probably make an online example that saves and restored camera positions for multiple panos.

how to make object to play an animation where it needs to play in unity?

I want to animate an object A so that, when it's certain distance from object, B it gets on top of B and does it's animation. I recorded key frames but animation is always played at initial location (where it was recorded originally) in other words I want animation to be depended on player's position not worlds position.
So how can I make a location depended animation?
Thanks!
create an empty parent object for the game object you wish to animate and move the parent instead then the object will animate relative to the parent

Blender: Different constraint influence between multiple animations

I’m using multiple animation in blender (multiple Dope Sheets )
And I’m trying to animate an arm that have an inverse kinematic constraint attach to it. But sometimes I don’t want use it, so I set the influence to 0.
The “problem” when I do this it propagates the changes to all previous animations even if the channel is protected.
Anyone knows a some way to get around this situation?
In blender almost any value can be keyframed, not just the location, rotation and scale of bones and objects. Any value that can be keyframed can also be controlled by a driver.
You can keyframe the influence value of the constraint the same as any other displayed value. Key it at 0.0 or 1.0 on the first frame and it will stay that way for the whole action. You can also keyframe it to turn on/off during the animation.
You can either RMB on a value and select insert keyframe or press I while the cursor is over the value.
The problem is if I have two animations ( animantion1 and animantion2 ) that when I turn off IK constraint in animation2 it also turns the IK in the animantion1 and it mess up with the previous animation.
I discovery that what I was trying to accomplish is the same of use FK/IK in the same animation.
The solution is instead insert keyframes with location and rotation LocRot, insert the keyframes with Visual LocRot.
Get the idea form this tutorial It explains it around 14:42.

Unity3d Updating position with animation simultaneously

I have an animation for humanoid models to simulate climbing. I have been looking for a way to stimulate this animation when the model comes next to the window. I used the triggers to determine where the model is and it worked. However, when I execute the animation, the position of the model is not being updated according to the animation. I am using offmesh links and nav mesh agent and I disable nav mesh agent when the model triggers. How can I use the animation and provide the update simultaneously?
Animation Properties
Thanks in advance.
I don't think the animation should take care of the movement. You should control that somewhere else. You could make the animation climb from y = 0 to 5 but then it won't work if your ladder is at y = 3.
You'd better have a method that is called from the animation using AnimationEvent so that when you trigger the animation, it also triggers a movement of the object upwards/downwards regardless of the current position of the object. It would simply use Translate and disabled input until the animation ends.

Unity Mecanim Scripting Dynamic Animation

I have a scene with one fully-rigged model of human body
and I would like to users could make their own animations by transforming the model.
I am talking about an app with time-line and possibility of rotating certain muscles.
Could you please recommend me some way how to do that?
I can imagine storing some information about model state in certain times.. but I do not know how to save it as an animation.
You can't edit animations at runtime. You can create an animation from scratch and use AnimationClip.SetCurve to build up your animation, but you can't access the curves directly at runtime.
However in an editor script you can use the AnimationUtilitys to modify an Animationclip, but of course only in the editor since this is an editor class.
Answer picked from this thread.
I think best possible solution for you is to create many different animations for every body part by your own and let user to choose different combinations of animations (if you are using Animator or Animations). Or you can split model by body parts and let user change transform parameters with iTweens (move from A to B and change angle from C to D). Then u can easily save object's "from" transform and object's "to" transform and use it as animation.

Resources