create bone lag
I am constraining a bone to the head, following the tutorial here: https://www.youtube.com/watch?v=6SYBmg8O6Fg&t=1611s
This works. I want to have additional bones follow the head, but have them lag behind - to act like a floppy antennae. My guess is that I need to use getTime() or something to add a lag. But I can't seem to figure it out.
Anyone have some ideas or samples?
Thanks,
Dale
Hi Dale,
For waiting for things, you should be using DelayedCallback. See example here:
https://lensstudio.snapchat.com/api/classes/DelayedCallbackEvent/
Or something similar to what Peter posted here:
https://support.lensstudio.snapchat.com/hc/en-us/community/posts/360015125163-Delay-on-Particle-Object-
Goodluck
will this work for something that I want to happen every frame?
If you want it to happen every frame, here's a event you can use for that
https://lensstudio.snapchat.com/api/classes/UpdateEvent/
My approach is to call the delayEvent in the updateEvent.
does that sound correct? if I do that, do the variables in the updateEvent carry into the delayEvent?
In the updateEvent, I am getting the head rotation and applying it to bone 1...and then in the delayEvent, I am matching that rotation 1 second later...
it isn't working yet, but is that to correct approach?
thanks,
Dale
my approach doesn't seem to work...I guess if I am calling the delayedEvent.reset(1) every frame, it never gets called -- just gets pushed back
var delayedEvent = script.createEvent("DelayedCallbackEvent");
delayedEvent.bind(function(eventData)
{
print("delay is over");
});
function onUpdate()
{
delayedEvent.reset(1);
print("delay has started");
}
var updateEvent = script.createEvent("UpdateEvent");
updateEvent.bind(onUpdate);
Hello,
You can do something like this,
That sleep function is working, but it is causing a huge frame rate drop. Since I am trying to update every frame with bone rotations, it immediately tanks the frame rate.
Any other ideas?
Yeah, i was about to edit the comment to suggest you to not use it due to fps drop.
Let me try to figure out another way for you.
Okay so,
I cant believe i used this long to figure out Lens Studio have a built in "frame updated" in the script.
I completely forgot about lens studio had that.
I have it working, but it is steppy. How can I get the rotation to be smooth?
// -----JS CODE-----
// @input float delayTime = 0
//@ui {"widget":"separator"}
// @input SceneObject bone1
// @input SceneObject bone2
// @input SceneObject bone3
// @input SceneObject root
// @input float spinSpeed = 2.0 {"widget": "slider", "min": 0, "max": 10.0, "step": 0.01}
var spinVal = Math.sin(getTime() * script.spinSpeed);
var spinVal2 = Math.sin(getTime() * script.spinSpeed) * 2;
// get the transforms
var rootTransform = script.root.getTransform();
var bone1Transform = script.bone1.getTransform();
var bone2Transform = script.bone2.getTransform();
var bone3Transform = script.bone3.getTransform();
var rootRotation = rootTransform.getWorldRotation();
var bone1Rotation = bone1Transform.getWorldRotation();
var bone2Rotation = bone2Transform.getWorldRotation();
var bone3Rotation = bone3Transform.getWorldRotation();
var bone1RotNew = rootRotation.multiply(bone1Rotation);
var bone2RotNew = rootRotation.multiply(bone2Rotation);
var bone3RotNew = rootRotation.multiply(bone3Rotation);
// bone1Transform.setWorldRotation(bone1RotNew);
bone1Transform.setLocalRotation(rootRotation);
// bone1Transform.setLocalRotation( quat.quatFromEuler( 0.0, 0.0, spinVal ) );
// bone2Transform.setLocalRotation( quat.quatFromEuler( 0.0, 0.0, spinVal ) );
var delayedEvent = script.createEvent("DelayedCallbackEvent");
delayedEvent.bind(function(eventData)
{
print("delay is over");
bone2Transform.setLocalRotation(bone1Rotation);
bone3Transform.setLocalRotation(bone2Rotation);
})
// Start with a 2 second delay
delayedEvent.reset(script.delayTime);
print("delay has started");
That would suggest that there are non animated textures introduced, such as you noted earlier as you can see on this page. In which case you would possibly as nicely simply use conduct scripts given that there are not any events to dam in the course of animation?
I am using Blender 2.75. So I have an armature for a pig. I used IK to have the legs always bend (a certain direction using a pole target) to connect with the target bone. I am pretty sure this is all set upright. I have animated the location (only) of the target bone in an attempt to make a walking animation. For further details, you may visit