Basically, the stuff I made in visual scripting does exactly what I want, except for 1 little detail, it does everything in 1 frame. When I press the “F” key, a certain bool becomes true, and the wings of a character rotate upwards, then downwards, then the character is pushed upwards. The thing is, I want the wings rotation to be performed over a certain amount of time, lets say, 0.250 seconds, same when rotating downwards, then, lets say, push the character upwards over 0.400 seconds. I have no idea how to do it, and no tutorial on youtube have been of any use =.=
I use the Timer Node quite a bit for time related things.
It takes a trigger pulse in then counts down the number of seconds entered.
itll trigger once from the start, then continuous like OnUpdate from Tick then one again when complete.
you can also get the elapsed time and remaining time to use in further calculations
I checked the documentation, which barely has any info about this “Timer” thing, still have no idea how to use it, so I decided to just randomly test it, and the result was a disaster. No idea why, but now my wing is just rotating non-stop
This whole visual scripting is supposed to be making things easier for non-programmers, but it still seems like arcane wizardry to me =.=
yeah no, it’s basically an alternative way to input code if you ask me.
still need to follow every rule like order of operations and use the correct things.
just removes the majority of the spelling issues and makes it more obvious what values go in and come out.
actually my preferred method nowadays lol
but yeah you’re rotating the wing -40 on the y every frame for 1 second, then when the timer is done, you rotate it again by +40 once and translate +1 and setting flappwings to false.
Here in this example, I’m using two timers. one to control flap down time and the next to controll flap up time.
the % remaining needs to be hooked into a variable to hold the value (as it cannot be fetched dynamically).
but all you need to do to invert the value is to multiply the value by -1. this way I can use the same value to control both directions.
Also, note how the rotation node differs to accept the local or world Eular, and how I’m using On Key to detect the F key press.
uh you’d probbly want to use the animator do make wings move but here you go
But on the plus side, you would be learning things that carry over to the rest of unity code ^.^
Sorry to bother you, but this is still not working. I don’t know the reason, but I do know the problem. It seems to be prioritizing the amount of time spent rotating, rather then the rotation value in the variable. So, the longer it rotates (lets say 10 seconds) the more it rotates. It’s basically ignoring the rotation value in the variable. If I want the wing to rotate 60 degrees upwards, then 60 downwards, then I have to set the timer to an amount of time enough to get the wings to 60 degrees… but i want to achieve a 60 degreees rotation in a fraction of a second, not in like 2 seconds which is how long it takes right now.
I’ll post the link to the screenshot here since it seems to have been resized
https://ibb.co/5r6rTsV
What is the ultimate goal that you want to achieve?
what is important for this code to suit your needs in other words.
do you simply want to rotate wings for the look?
it also seems like this code would be mirrored on a second wing, is that what you’re tryin’ to do?
The goal is to achieve specific rotation on wing (60 degrees) over a specific amount of time (0.250 seconds). If the rotation is not 60 degreees, it wont look good, if the amount of time is not 0.250 seconds, it will affect the gameplay. The player will be spamming the “flapping wings” key to make sure the character stays in the air. And yeah, it will be mirrored on a second wing, but I can’t get it working on the first wing yet =.=
First a disclaimer. This sort of this would traditionally be handled by the Animator. But for the sake of learning, may as well cover this. One of the reasons you may want to use the animator instead would be to have better control over the motion of your character. For example, you may want to have alternate styles of flapping. You would then create 3 animations and just tell the Animator to play the appropriate action. You can even transition or blend between them. it’s all built into Unity! But, put a pin in that and let’s move on. We need somthin’ that works for you now.
Okay so what I’ve done is created an extremely rough bird player character based off of a simple ridged body. Let me explain how the hierarchy is laid out. I’ve got a ‘BodyCapsule’ Game Object that includes a Capsule Collider, a RigidBody and a Script Machine Component. This will act as the main body. Then I’ve got an EmptyObject named Wing1 and Wing2 as Children of the main body to act as a rotation point and a container for the wing graphics to rotate around. then finnaly the wing meshes themselves are children of the wing empty object.
having the hierarchy setup like this, will help later when we want to apply the rotations. Basically all the code is held on the Player controller, while it references the wing objects inside. Kind of more slick then having two codes just to flap wings.
Here is the overall Zoomed out graph that shows each section, basically divided up by function. Note that this triggers only when the player presses F and if you want it to trigger on a Bool, you’ll need only add an IF or AND. Couldn’t quite see how you have the flap triggered,
Here is how i’ve set up the vars
Here I detect if F key is Up or down toggle appropriately. (Note Start On is UNCHECKED)
This just sets IsFlapping to True when the key is pressed and false when up.
Here we see if IsFlapping is true then ONCE run the timers by the TotalFlapTime. (devided by 2 because there’s two timers) Note that the ONCE node is reset when the timer is complete. Basically this locks the animation of the wings so it cannot be interrupted by spamming the key press. In other words, you can’t flap if you’re alredy flapping.
Here I fetch the reference to the wing1 and wing2 objects using the Transform.GetChild. So the code can apply the rotation only to those objects. They’re plugged into the Transform.LocalRotations.
Here are both wings being rotated using the Set Local Rotation Node. Note that I’m splitting the XYZ values from Get Local Rotation with an EXPOSE node that has the Static checkbox unchecked.
So we get the local rotation of the empty wing objects, seperate the X axis because that is how we want to rotate, We then add the result of the Timer output multiplied by the Max Rotation before Appling the rotation value with Set Local Rotation. Note how the Lower cluster is multiplying the value by -1 to invert the value for the mirrored wing.
and when the first Timer Starts, we just apply a relative force to the main body in an upward direction by some force value. Set to Velocity Change