I used the key “E” to grab but I see that I need to keep pressing the “E” to keep grapping the statue or it will be released instead how to make the key function like toggle ?
- List item
I used the key “E” to grab but I see that I need to keep pressing the “E” to keep grapping the statue or it will be released instead how to make the key function like toggle ?
You have been taught everything you need in order to implement this yourself. Have you had a go at this?
yes using bool variable.
And what issues are you having with that?
nothing like to learn different ways to do the same thing. I meant in the input dialog when I define the action / axis keys. If there is an option to make the key work as need to be hold on pressed and another option to make it work like toggle need to be pressed twice for the release event to occur
I’m a little confused now. You’re asking how to toggle grab but you’ve already successfully implemented it?
I wrote the reason in the previous post.my solution was using bool variable in C++ code, if you can not understand what I mean you can leave it
I understood this. What I don’t understand is the question in the OP.
“How do I make the key toggle”
But you’ve already done it?
after I post the question I made a try to use bool variable and it work now I just see if my solution is the only one that can work.
I think a language barrier may be an issue here in the understanding of what is being asked.
Current implementation
You press E and the object is picked up but when the key is released it drops the object
What is wanted
You press E and the object is “held” and then dropped on pressing the key again
A boolean is still the way to go but the way the keypress is implemented would be the issue here rather than having it release on key being released.
This is more complex in that it would probably need something like an anchor point to become a child of and then when you want to release the object have it look though the hierarchy of the character for an object attached to said anchor point and then unchild it.
Hopefully i have understood correctly what you have been trying to ask.
Very rarely is there just one solution to any given problem. For this, think to yourself, is a bool really needed? Does the component already have a way to tell me if the physics handle has grabbed something or not?
I was thinking this way to check
if (PhysicsHandle == nullptr)
But in the same moment I press the grab key the PhysicsHandle would not be null so when I release if I checked for null it would be false and the release code will execute so once I press and release the statue will fall as well. However I dont want to take more of your time in this, you must have many other questions to answer so boolean variable is enough for me for now. Thanks
GrabKeyOn = !GrabKeyOn;
That’s the physics handle component itself which (hopefully) is never null.
You’ve already used what I’m suggesting in the release function. If the physics handle component is grabbing something then GetGrabbedComponent()
will return a non-null value in which you would want to release, otherwise it will return nullptr in which case you want to grab. So it’s simply
if (PhysicsHandle)
{
if (PhysicsHandle->GetGrabbedComponent())
{
Grab();
}
else
{
Release();
}
}
I dont understand where I should put this code ?
Create a new function.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.