NodeCanvas Forums › General Discussion › Rotate as long as key is pressed
Hey there,
I like the UI and everything, but I think the documentation just doesn’t work for me. I need hands on tutorials that explain how to solve certain things with the tools nodecanvas offers.
Today I wanted to make a small turntable control with NC, but didn’t came close to get something out of it. I didn’t found a way to have something rotate as long as I press a key.
In the end I built it with FlowCanvas.
How would I do it with NC?
Thanks!
Hello,
Im sorry to hear that. If you have any suggestions for the documentation, by all means do let me know.
There is also actually a scene in the downloadable examples that does what you were after with an FSM.
Bellow are two possible way of doing this, one with a Behaviour Tree and another with an FSM in NC.
The Action Task used here in both cases is “Script Control/Execute Function” and within which the “Transform.Rotate” function has been selected.
Please let me know if this works for you.
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh
Thank you Gavalakis!
I didn’t found that myself. Don’t get me wrong, I like NC and FC very much and I am making the switch from playmaker. It’s just that there are many videos, tutorials and even courses on playmaker, that gets you up to speed very quickly (in the end you just need to know some gamelogic and triggers).
For NC, some videos or short image heavy tutorials on some standard solutions would be cool, e.g. making a simple player controller (tank would be easiest?, setting up triggers and zones, shooting a bullet, implementing a health system, a simple enemy for the player, relationship between bullet, enemy and health, updating gui values. That was just an idea, you could use a tank, a car or a FPS character (or something that needs mecanim animation, to show how that would work with NC). Broken into small systems that work together and give you enough to start on your own ideas.
Another question, how do I manage two keystrokes at once? e.g. ‘w’ for translation forward and ‘a’ for rotating left?
There was an answer to my question on this forum, but unfortunately the images were gone (seemed to be a forum crash in the past?).
Again, thank you very much for your thourough support and great plugins!
btw, may I ask, if you work alone on this or if you took some safety measures just in case you get ill or break an arm or something?
I’d even model you everything you need for a tutorial.
Hey!
Sorry for the late reply and thanks a lot for your feedback. I am very glad you like the plugins! 🙂
Modeling is not the real issue (although I greatly appreciate your offer!), but rather a language barrier. Because I am Greek, I don’t really speak English fluently for a voice over video tutorial otherwise such would already exist. For that reason, I’ve already got in contact with a guy who is making Unity video tutorials/courses professionally (on Digital Tutors) for this task and we will begin working on this as soon as possible. I will certainly keep your suggestions in mind for when we get started 🙂
There are two nicely working together actions for making an object move on input, those being the “Get Input Axis” and “Input Move”, which you can add both in an Action List, as shown bellow:
This will make the object move with “W/S” and turn with “A/D”, both being defined in the Unity Input Manager (Edit/Project Settings/Input) as Vertical and Horizontal respectively by default.
A similar usage can also be found in the example scene “Turret Targeting” for controlling the sphere player.
Please let me know if that works for you.
Thanks again for your feedback and input!
(PS: Yes, I’m working alone on these plugins and I really hope I don’t break anything as well 🙂 )
Join us on Discord: https://discord.gg/97q2Rjh
Thank you Gavalakis,
unfortunately, I don’t want to move the player in a regular fashion, I want to drive a customized turntable with keys. What’s the standard way for a BT to work with two inputs at the same time? parallel I guess (that’s what I found in the thread with the missing images)?
Thanks for taking the time and supporting us noobies.
Wish you all the best!
Hello,
I tried a similar request some time ago
This is what worked for me…
You can try with the parallel
Composite. Create two branches down
Assign a decorator (conditional) to
Each of this branches, add a condition
Task for keyboard input so you assign
The keys you like
Then create a branch down from
Decorator 1 and create a task for
movement
Then create a branch down from
Decorator 2 and create a task for
Rotation
Cheers!
Hello,
Yes, one way is to indeed use a Parallel node like you suggest, but an alternative way (at least specifically for a turntable) would still be to use the InputAxis and InputMove action tasks as explained above. I have attached here an example scene for you.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Thanks to the both of you, I tested your solutions and I have only few questions left:
For the first idea (chocolacode), each keystroke only delivers an impulse, no continued movement. How would I change that plan to allow for continuos movement, if I hold down the key?
And about Gavalakis version: My turntable needs not only rotation around y-axis (your example) but also around x-axis (to look on top). Can I do this with your InputAxis/InputMove actions aswell?
Thanks a lot, it is fun to learn NC and FC!
Hey,
For chocolacode’s suggestion, you simply need to change the Check Keyboard Input from “Down”, to “Pressed”. As such the conditional decorator will evaluate as long as the key is pressed/hold.
For my suggestion, if you simply want rotations and no movement, you can use GetInputAxis, then a “Script Control/Execute Function” task and select “Transform.Rotate(float, float, float)”. Then link the x, y, z parameters of that Rotate Function to the variables saved by the GetInputAxis. For example:
Let me know if either of those work for you.
Cheers!
Join us on Discord: https://discord.gg/97q2Rjh
Excellent!
Big, big thank you!