Jump to content
  • Advertisement
Harry Loretz

C++ Having a little trouble with my "Invisibility command" please help.

Recommended Posts

20 hours ago, Alberth said:

I would suggest to cleanup the structure, you seem to have too many variables, and you can't say how it works exactly.

Your invisibility has 3 states

  • ready for use
  • being invisible
  • recovering (that is, preparing for next use)

You have one variable that defines in what state it is (ie one of the above 3 values). In the first state, the user can start being invisible, the 2nd and 3rd state have a timer (you can have 1 timer as far as I can see), where the state changes when the timer runs out.

 

12 hours ago, Zakwayda said:

I think the next point of confusion is as follows. Above, you suggest that the 'stop' and 'cooldown' timers run concurrently, but your code suggests they run sequentially. So there seems to be a disconnect there. Maybe a couple questions will help clear things up:

- Once the character becomes visible again (due to the timer expiring), how long do you want to have to wait before the character can become invisible again? One second, or six seconds? (If the timers run concurrently it'd be one second, but if they run sequentially, as they appear to in your code, it'd be six seconds.)

- Assuming your code works so far, how long do you have to wait in practice after the character becomes visible to make it invisible again? Is it relatively short, like one second, or relatively long, like six seconds?

Here is a link to that video, it should be obvious which video it is. I am going to do some more code towards this today hopefully find a solution. I will neaten up the code to so i better understand it myself. I am really unsure how to do this, like if i wanted to become visible from invisible anytime i choose then would that be a "if" statement, or should the code be separate? 

 

https://www.facebook.com/NextLevelEntertainmentX

Share this post


Link to post
Share on other sites
Advertisement
42 minutes ago, Harry Loretz said:

Here is a link to that video...

From the video, it looks like the character is invisible for about 5 seconds and that the cooldown period after the character becomes visible is about 6 seconds. Would you agree? (I ask because earlier you said you thought the cooldown period was 1 second, so I just want to make sure we're all on the same page here.)

Share this post


Link to post
Share on other sites

ToggleVisibilityHonestly mate, simplify your problem you are to early in to turn your code into a big ball of mud

the easiest way would be to just remove the negate variable entirely

Use one timer for both the cooldown and the automatic deactivate...

void AOmniCharacter::TryToggleVisibility()
{

    If(!GetWorldTimerManager().IsTimerActive(InvisibilityHandle, this, &AOmniCharacter::TryStopInvisibility, Invisible, true))

        { 

GetInvisibleMesh()->ToggleVisibility();
        ACharacter::GetMesh()->ToggleVisibility();

        HetWorldTimerManager().SetTimer(InvisibilityHandle, this, &AOmniCharacter::StopInvisibilty, InvisibilityStop, true);
    }

}

just set the timer value based on the visibility state of the mesh maybe then it's one function for all

Sorry this was a mess it's late and I am on my phone

Share this post


Link to post
Share on other sites
13 minutes ago, Zakwayda said:

From the video, it looks like the character is invisible for about 5 seconds and that the cooldown period after the character becomes visible is about 6 seconds. Would you agree? (I ask because earlier you said you thought the cooldown period was 1 second, so I just want to make sure we're all on the same page here.)

Yes i agree with you, Yeah i was wrong earlier i thought they ran side by side before. But they are sequential as you said before. I think we are on same page, i am going to try Andi's method, this could be what i am looking for.

4 minutes ago, Andi "Debug" Ireland said:

ToggleVisibilityHonestly mate, simplify your problem you are to early in to turn your code into a big ball of mud

the easiest way would be to just remove the negate variable entirely

Use one timer for both the cooldown and the automatic deactivate...

void AOmniCharacter::TryToggleVisibility()
{

    If(!GetWorldTimerManager().IsTimerActive(InvisibilityHandle, this, &AOmniCharacter::TryStopInvisibility, Invisible, true))

        { 

GetInvisibleMesh()->ToggleVisibility();
        ACharacter::GetMesh()->ToggleVisibility();

        HetWorldTimerManager().SetTimer(InvisibilityHandle, this, &AOmniCharacter::StopInvisibilty, InvisibilityStop, true);
    }

}

just set the timer value based on the visibility state of the mesh maybe then it's one function for all

Sorry this was a mess it's late and I am on my phone

Hey Andi, i will try your method, what you wrote seems to simplify things. Thanks for your reply to i appreciate all the feedback and help.
  

 

 PlayerInputComponent->BindAction("GoInvisible", IE_Pressed, this, &AOmniCharacter::GoInvisible);
 PlayerInputComponent->BindAction("GoInvisible", IE_Pressed, this, &AOmniCharacter::GoVisibleWhileInvisible);


void AOmniCharacter::GoVisibleWhileInvisible()
{
    if (VisibilityNegate == false)
    {
        
        GetWorldTimerManager().ClearAllTimersForObject(this);
        GetInvisibleMesh()->ToggleVisibility();
        GetMesh()->ToggleVisibility();
        GetWorldTimerManager().SetTimer(InvisibilityHandle2, this, &AOmniCharacter::ResetInvisibilitySpell, InvisibilityCooldown);
    }
}

i tried this along with my original code on the first post, but it doesn't work. I thought this made sense but it totally ignores the timer and confuses the input and makes timers and input out of wack. I also added a new Ftimerhandle here. This is just to show you guys what my current understanding of C++ is like, so bare with me :)

Share this post


Link to post
Share on other sites
38 minutes ago, Andi "Debug" Ireland said:

ToggleVisibilityHonestly mate, simplify your problem you are to early in to turn your code into a big ball of mud

the easiest way would be to just remove the negate variable entirely

Use one timer for both the cooldown and the automatic deactivate...

void AOmniCharacter::TryToggleVisibility()
{

    If(!GetWorldTimerManager().IsTimerActive(InvisibilityHandle, this, &AOmniCharacter::TryStopInvisibility, Invisible, true))

        { 

GetInvisibleMesh()->ToggleVisibility();
        ACharacter::GetMesh()->ToggleVisibility();

        HetWorldTimerManager().SetTimer(InvisibilityHandle, this, &AOmniCharacter::StopInvisibilty, InvisibilityStop, true);
    }

}

just set the timer value based on the visibility state of the mesh maybe then it's one function for all

Sorry this was a mess it's late and I am on my phone

I tried this method i believe i wrote it correctly, where it says   "If(!GetWorldTimerManager().IsTimerActive(InvisibilityHandle, this, &AOmniCharacter::TryStopInvisibility, Invisible, true))" within the brackets it says that it needs to be a boolean statement. 

 



 

Share this post


Link to post
Share on other sites

    If(!(GetWorldTimerManager().IsTimerActive(InvisibilityHandle)))

I'm in bed on my phone after a crunch day so it was hand written psuedo sloppy copy paste try that if not press f12 on the istiner active to have it take you to the function def and see what's wrong I'll check it all tomorrow for you

Share this post


Link to post
Share on other sites
4 minutes ago, Andi "Debug" Ireland said:

    If(!(GetWorldTimerManager().IsTimerActive(InvisibilityHandle)))

I'm in bed on my phone after a crunch day so it was hand written psuedo sloppy copy paste try that if not press f12 on the istiner active to have it take you to the function def and see what's wrong I'll check it all tomorrow for you

I appreciate that a tonne Andi, I will give it a go :) thankyou for your time.

Share this post


Link to post
Share on other sites

Hey so i Figured out how to make this code work the way i want it to, but i have 1 minor issue left. The issue i have now is that I want the PlayerInput to be "pressed" for both of these, but if i do that they conflict with the code shown below. I will show you guys what i have so far.  So close to having this finished :) i really appreciate all the help. 

 

To simplify i want the controls to work like (press "1" to go invisible, press "1" to Become Visible while invisible)

 

PlayerInputComponent->BindAction("GoInvisible", IE_Pressed, this, &AOmniCharacter::GoInvisible);
PlayerInputComponent->BindAction("GoInvisible", IE_DoubleClick, this, &AOmniCharacter::GoVisibleWhileInvisible);

void AOmniCharacter::GoInvisible()
{
    if (!(GetWorldTimerManager().IsTimerActive(InvisibilityHandle2)) && (!(GetWorldTimerManager().IsTimerActive(InvisibilityHandle))))
    {
        GetInvisibleMesh()->ToggleVisibility();
        GetMesh()->ToggleVisibility();
        GetWorldTimerManager().SetTimer(InvisibilityHandle, this, &AOmniCharacter::StopInvisibilty, InvisibilityStop, false);
    }
}

void AOmniCharacter::GoVisibleWhileInvisible()
{
    if (GetWorldTimerManager().IsTimerActive(InvisibilityHandle))
    {
    GetWorldTimerManager().ClearTimer(InvisibilityHandle);
    GetInvisibleMesh()->ToggleVisibility();
    GetMesh()->ToggleVisibility();
    GetWorldTimerManager().SetTimer(InvisibilityHandle2, this, &AOmniCharacter::ResetVisibility, InvisibilityCooldown, false);
    }
}

void AOmniCharacter::StopInvisibilty()
{
    {
        GetInvisibleMesh()->ToggleVisibility();
        GetMesh()->ToggleVisibility();
        GetWorldTimerManager().SetTimer(InvisibilityHandle, this, &AOmniCharacter::ResetVisibility, InvisibilityCooldown, false);
    }
}

void AOmniCharacter::ResetVisibility()
{
}

Share this post


Link to post
Share on other sites

Yes Yes! here we go!
I finished the code, just letting you guys know.
this is what works. I had to make 3 FTImerHandles to make it work though. 

PlayerInputComponent->BindAction("GoInvisible", IE_Pressed, this, &AOmniCharacter::GoInvisible);

void AOmniCharacter::GoInvisible()
{
    if (!(GetWorldTimerManager().IsTimerActive(InvisibilityHandle2)) && !(GetWorldTimerManager().IsTimerActive(InvisibilityHandle)) && !(GetWorldTimerManager().IsTimerActive(InvisibilityHandle3)))
    {
        GetWorldTimerManager().SetTimer(InvisibilityHandle, this, &AOmniCharacter::StopInvisibilty, InvisibilityStop, false);
        GetInvisibleMesh()->ToggleVisibility();
        GetMesh()->ToggleVisibility();

    }
    else if (GetWorldTimerManager().IsTimerActive(InvisibilityHandle))
    {
        GetWorldTimerManager().ClearTimer(InvisibilityHandle);
        GetWorldTimerManager().ClearTimer(InvisibilityHandle3);
        GetWorldTimerManager().SetTimer(InvisibilityHandle2, this, &AOmniCharacter::ResetVisibility, InvisibilityCooldown, false);
        GetInvisibleMesh()->ToggleVisibility();
        GetMesh()->ToggleVisibility();
    }
}

void AOmniCharacter::StopInvisibilty()
{    
    if (!(GetWorldTimerManager().IsTimerActive(InvisibilityHandle2)))
    {
        GetWorldTimerManager().SetTimer(InvisibilityHandle3, this, &AOmniCharacter::ResetVisibility, InvisibilityCooldown, false);
        GetInvisibleMesh()->ToggleVisibility();
        GetMesh()->ToggleVisibility();
        
    }
}

void AOmniCharacter::ResetVisibility()
{
}
 

 

Much appreciation everyone :) 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!