🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

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

Started by
18 comments, last by Harry Loretz 4 years, 11 months ago

Hey there everyone, I am quite new to C++ and have implemented some code for an invisibility spell/command. What currently happens is I press "1" then the character goes invisible, it activates a timer (InvisibilityStop) timer plays out, then the character reappears on it's own as intended, while another timer(InvisibilityCooldown) is playing so i can't immediately go invisible again. I just want to be able to go Visible whenever i am Invisible but i want there to be a corresponding timer so i can't go invisible right away, i also would like this timer to be the remaining time of the "InvisibilityCooldown". Here is the code. 

void AOmniCharacter::GoInvisible()
{
    if (VisibilityNegate)
    {
        GetInvisibleMesh()->ToggleVisibility();
        ACharacter::GetMesh()->ToggleVisibility();
        VisibilityNegate = false;
        GetWorldTimerManager().SetTimer(InvisibilityHandle, this, &AOmniCharacter::StopInvisibilty, InvisibilityStop, true);
    }
}

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

void AOmniCharacter::ResetInvisibilitySpell()
{
    VisibilityNegate = true;

 

 

Please help, i can't figure this out, I also do not wish to tie this spell into a mana system.

Thankyou.

Advertisement
51 minutes ago, Harry Loretz said:

I just want to be able to go Visible whenever i am Invisible but i want there to be a corresponding timer so i can't go invisible right away, i also would like this timer to be the remaining time of the "InvisibilityCooldown".

This part seems confusing (or I'm having trouble parsing it at least). If no one else jumps in, maybe you could take another run at describing what behavior you're wanting that you haven't already implemented.

Also, 'VisibilityNegate' seems a bit confusing as a variable name (to me at least). It seems to be an 'is visible' flag (that is, it's true when the character is visible, false when invisible) - is that what it is?

Quote

...I also do not wish to tie this spell into a mana system.

For those of us for whom it may not be immediately apparent what this means, maybe you could elaborate, if it's relevant at least (if it's not directly relevant, maybe you could clarify that).

Thank you for your reply Zak,, Yes you are right VisibilityNegate is a boolean, true or false, I was experimenting with different types of code so VisibilityNegate worked for me, yes it is a visibility flag. 

When i said i don't wish to tie in this spell to a mana system, i am just saying that i don't want the invisibility to have anything to do with mana drain. I just said it in case. It's not important really.

All i want is to appear "visible" whenever i appear "invisible", any time i choose during "Invisibility being active". But the consequence of going visible will be that you will have to wait until you can go invisible again. Simply put. I also want that consequence i mentioned earlier to work in a way where "if i choose to go visible while invisible, i will have to wait for a timer which is equal to the difference of the cooldown timer i have. so lets say i "goInvisible" the cooldown timer goes for 5seconds, at 2 seconds i go visible, so now i have to wait 3 seconds. or if i choose to go visible at 4seconds into the cooldown timer, i will have to wait 1 second before i can go invisible again.

Much appreciation Zak,

also i have a (stopInvisibility) timer too so that has to be cleared when going visible, but i think i know how to do that.

also you may have noticed i have 2 meshes, Invisiblemesh has a completely transparent material attached so you appear invisible with a shadow too.

42 minutes ago, Harry Loretz said:

Thank you for your reply Zak,, Yes you are right VisibilityNegate is a boolean, true or false, I was experimenting with different types of code so VisibilityNegate worked for me, yes it is a visibility flag.

Actually, now that I look at it again, I don't think I had the right idea about what that variable does. The name still seems a little confusing to me, but moving on :)

Quote

All i want is to appear "visible" whenever i appear "invisible", any time i choose during "Invisibility being active". But the consequence of going visible will be that you will have to wait until you can go invisible again. Simply put. I also want that consequence i mentioned earlier to work in a way where "if i choose to go visible while invisible, i will have to wait for a timer which is equal to the difference of the cooldown timer i have. so lets say i "goInvisible" the cooldown timer goes for 5seconds, at 2 seconds i go visible, so now i have to wait 3 seconds. or if i choose to go visible at 4seconds into the cooldown timer, i will have to wait 1 second before i can go invisible again.All i want is to appear "visible" whenever i appear "invisible", any time i choose during "Invisibility being active". But the consequence of going visible will be that you will have to wait until you can go invisible again. Simply put. I also want that consequence i mentioned earlier to work in a way where "if i choose to go visible while invisible, i will have to wait for a timer which is equal to the difference of the cooldown timer i have. so lets say i "goInvisible" the cooldown timer goes for 5seconds, at 2 seconds i go visible, so now i have to wait 3 seconds. or if i choose to go visible at 4seconds into the cooldown timer, i will have to wait 1 second before i can go invisible again.

I think I almost understand that. But the way you describe it above, it sounds like the 'cooldown' timer runs while you're invisible and determines how long you remain that way, whereas based on your original post I was under the impression the cooldown timer runs after you become visible again and determines how long you have to wait before you can become invisible again.

To put it in question form, what are all the timers in your original example code, and what do they time? (I see 'stop' and 'cooldown', and I have a guess as to what they time based on that, but my guess doesn't seem to match your more recent description.)

1 hour ago, Zakwayda said:

Actually, now that I look at it again, I don't think I had the right idea about what that variable does. The name still seems a little confusing to me, but moving on :)

I think I almost understand that. But the way you describe it above, it sounds like the 'cooldown' timer runs while you're invisible and determines how long you remain that way, whereas based on your original post I was under the impression the cooldown timer runs after you become visible again and determines how long you have to wait before you can become invisible again.

To put it in question form, what are all the timers in your original example code, and what do they time? (I see 'stop' and 'cooldown', and I have a guess as to what they time based on that, but my guess doesn't seem to match your more recent description.)

It's hard to explain, thanks for being patient with me. So i can't actually say for sure that my timers are the best setup, but the InvisibilityStop is the timer which determines how long you stayed invisible for but the cooldown timer seems to run at the same time as the invisibilitystop timer, they use the same FTimerHandle. I'm very new to all this. So yeah i think the cooldown runs at the same time, or very close to that . I copied the timer code i got from a "Dash" tutuorial i followed. It may not be the best way for timers.

i have in the constructor 

InvisibilityStop = 5.f;

InvisibilityCooldown = 6.f;

I really appreciate this man :) 

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.

59 minutes 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.

Thankyou for your reply Albert, I will make a video soon and upload a link here it will be a better explanation. I thought about having 1 timer, but i can't because i need 1 time set for the character to become visible from invisible, and i need another time set for a cooldown, so the character/player can't become invisible straight away again. I wrote in a reply to Zak that i am new to coding and used Code i got from a character dash movement tutorial.

You are right i should clean up the structure, i was thinking about that a few minutes ago. I Understand most of this code, having a bit of trouble with the parameters, which i believe are the things inside of the ()brackets.

Please note, i am new to C++ but am doing it fulltime. 

I appreciate your reply Albert 

9 hours ago, Harry Loretz said:

It's hard to explain, thanks for being patient with me. So i can't actually say for sure that my timers are the best setup, but the InvisibilityStop is the timer which determines how long you stayed invisible for but the cooldown timer seems to run at the same time as the invisibilitystop timer, they use the same FTimerHandle. I'm very new to all this. So yeah i think the cooldown runs at the same time, or very close to that . I copied the timer code i got from a "Dash" tutuorial i followed. It may not be the best way for timers.

i have in the constructor 

InvisibilityStop = 5.f;

InvisibilityCooldown = 6.f;

I really appreciate this man :) 

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?

I think it is one second i will check, I don't have great editing software but i will make a short video and upload it to my dev page on facebook and put the link here. it should work sequentially but it doesn't seem to. I will do that today, i just woke up :) 

This topic is closed to new replies.

Advertisement