#i sent you the code in update thought it
1 messages Β· Page 1 of 1 (latest)
Lets message here, this will be easier.
Having a hard time keeping track with everything else going on in that channel.
beatiful
yea
ok so
first this is the full code
and here is update
private void Update()
{
// ground check
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.3f, whatIsGround);
ClimbAble = Physics.Raycast(transform.position, new Vector3(1, 0, 1), playerHeight * .5f + .3f, whatIsGround);
ClimbAbleMinus = Physics.Raycast(transform.position, new Vector3(0, 0, -1), playerHeight * .5f + .3f, whatIsGround);
MyInput();
SpeedControl();
StateHandler();
FovBooster();
StateSpam();
Dashing();
Climbing();
// handle drag
if (grounded)
rb.drag = groundDrag;
else
rb.drag = 0;
}
IEnumerator Climbing()
{
if (Input.GetKey(climbKey) && ClimbAble == true)
{
ClimbAble = false;
yield return new WaitForSeconds(5f);
rb.AddForce(0, climbDistance, 0, ForceMode.Force);
Debug.Log("Climbed");
state = MovementState.climbing;
Invoke(nameof(readyToClimbNow), climbingCooldown);
}
}
=-
A Coroutine can be called like a method, but won't yield if done so.
how do i make yield
Your main goal is just for ClimbAble to be false for 5f right?
yup
Okay then I would make that specifically a coroutine. Something like
IEnumerator ClimbingDelay(){
yield return new WaitForSeconds(5f);
ClimbAble = true;
}```
wont that litteraly just turn it on after 5 seconds
when im touching a wall the bool is true when i press the climb key i dont want to be able to climb on the same wall again
so i dont fly up the sky
i want a cool down for the Climbing
mh, okay. Then we will want to check if we are currently climbing still?
yes
Then the State looks like a good source for that?
if i press v two times or even hold it i get sent flying
ok
the state is already there
if state is climbing climbable false
you mean?
Yes, so for the delay we could check if the state is climbing, if it isn't we set ClimbAble to True, and if it is still climbing we wait another 5 seconds?
no i want climable to only be true once im touching a wall
i already implomented a raycast for that
Ah, so if not climbing and also touching a wall?
actually i might make it so i cant climb while im in state air
cuz i do have a state air
Makes sense.
because imagine just falling onto a wall and fly out of upwards like what
So we can edit the coroutine to something like
IEnumerator ClimbingDelay(){
yield return new WaitForSeconds(5f);
if (/* Conditions to allow climbing again*/)
ClimbAble = true;
else
StartCoroutine(ClimbingDelay);
}```
this should work
while(state == MovementState.crouching){
ClimbAble = false;
}```
doesnt work :)
That would, though I think having the logic for when they play should be able to climb be in the coroutine will be easier. As it is being set false at just one spot as well.
i removed ienumerator lol
There are a few problems with the current coroutine we will need to get to.
private void Climbing()
{
if (Input.GetKey(climbKey) && ClimbAble == true)
{
while(state == MovementState.crouching){
ClimbAble = false;
}
rb.AddForce(0, climbDistance, 0, ForceMode.Force);
Debug.Log("Climbed");
Invoke(nameof(readyToClimbNow), climbingCooldown);
state = MovementState.climbing;
}
}```
Yeah the climbable function doesn't need to be a coroutine anymore.
It should climb but we need the delay still. So going with the previous code I posted you would just need to add a
StartCoroutine(ClimbingDelay);
to your method
Also I would suggest moving that state check into the coroutine also. And maybe move the crouch check out, as if we are inside the conditional already having climbable set to false because of a bad state won't stop it from climbing
IEnumerator ClimbingDelay(){
yield return new WaitForSeconds(5f);
if (ClimbAble == true) {
ClimbAble = true;
}
else
StartCoroutine(ClimbingDelay);
}```
what do i do
Ah so for the /* Conditions to allow climbing again*/ you want what ever logic needs to be true to allow the player to climb again.
the only logic it needs is to be not in air state
So the coroutine will take care of the delay, but in there put like the air state, and is climbing state.
And then the crouch can be outside of the if, though I wouldn't use a while, I would just use an if check before hand
rb
a while like that could cause an infinite loop and the editor to crash on you.
change
if (ClimbAble == true)
to not check if ClimbAble is true, but to check that the state isn't climbing/air
IEnumerator ClimbingDelay(){
yield return new WaitForSeconds(5f);
if (state != MovementState.air) {
ClimbAble = true;
}
else
StartCoroutine(ClimbingDelay);```
Basically, after 5 seconds if we aren't in the air, or climbing allow use to climb again, otherwise wait another 5 seconds.
Yeah that looks about right.
Also
while(state == MovementState.crouching){
ClimbAble = false;
}
could cause you problems. change it to an if
also probably move it out of where we are already climbing
wait
oh nvm
hoping it works
you really are tiring your self helping me thanks dude
i flew
coding can often take lots of small tweaks, as computers take things very literal. Also np, we all start somewhere, and this is nothing to some of the head pounders I have had to figure out.
man your better than some people in this server
ok so now what do we suppose is the problem
to me litteraly going to the heavens
Ah I don't think we are setting ClimbAble = false; anywhere currently
I can't at the moment, I am on my phone.
oh
dang
well so look
IEnumerator ClimbingDelay()
{
yield return new WaitForSeconds(5f);
if (state != MovementState.air)
{
ClimbAble = true;
}
else
{
StartCoroutine(ClimbingDelay());
}
}
private void Climbing()
{
if (Input.GetKey(climbKey) && ClimbAble == true)
{
while (state == MovementState.crouching)
{
ClimbAble = false;
}
rb.AddForce(0, climbDistance, 0, ForceMode.Impulse);
Debug.Log("Climbed");
Invoke(nameof(readyToClimbNow), climbingCooldown);
state = MovementState.climbing;
}
}
this is the code were working with
whats wrongg
Okay, give me one sec
ok
IEnumerator ClimbingDelay()
{
yield return new WaitForSeconds(5f);
if (state != MovementState.air)
{
ClimbAble = true;
}
else
{
StartCoroutine(ClimbingDelay());
}
}
private void Climbing()
{
if (state == MovementState.crouching)
{
ClimbAble = false;
}
if (Input.GetKey(climbKey) && ClimbAble == true)
{
ClimbAble = false;
rb.AddForce(0, climbDistance, 0, ForceMode.Impulse);
Debug.Log("Climbed");
Invoke(nameof(readyToClimbNow), climbingCooldown);
state = MovementState.climbing;
StartCoroutine(ClimbingDelay());
}
}
Try that, I moved the while to outside, set climbing to false at the start of climbing, and also added a call to the coroutine, as we weren't actually starting it at any point.
Yeah should be able to just replace the old code.
this might give us some trouble.
Invoke(nameof(readyToClimbNow), climbingCooldown);
I am not sure what is in that, but as long as it doesn't conflict we should be more or less okay.
still fly
ooof
wait
why dont we just say if im climbing then climable is false
and i just make it so one frame has enough force to jump me up?
yes
If your idea doesn't work I probably would have a second bool, something like CanClimb, and have that checked as well.
private void Climbing()
{
while(state == MovementState.climbing)
{
ClimbAble = false;
}
if (Input.GetKey(climbKey) && ClimbAble == true)
{
ClimbAble = false;
rb.AddForce(0, climbDistance, 0, ForceMode.Impulse);
Debug.Log("Climbed");
// Invoke(nameof(readyToClimbNow), climbingCooldown);
// state = MovementState.climbing;
// StartCoroutine(ClimbingDelay());
}
}
}```
i have put a // also at the ienu
prevnting errors
if this works i might breakdown
its been like 4 hours
Because basically the raycast will tell us if there is something to climb, and CanClimb would tell us if we are in a state that allow it.
i flew
I wouldn't use while though
i dont know if i should be happy or sad?
// state = MovementState.climbing;
you commented out the state being set to climbing XD
uncomment that, and turn the while to an if.
Did you get rid of that while? Whiles can cause unity to crash if the exit condition isn't reached.
no
hell n-
its while state is climbing ju st dont make climbabl e true\
like comeone thats not coplicated
{
ClimbAble = false;
}```
state is never set inside of it, so it will just keep setting ClimbAble to false untill the next iceage
if (state == MovementState.climbing)
{
ClimbAble = false;
}
Believe me I have done that to many times to count
i just close unity and hope my work didnt get fricked up?
eh, unfortunately yeah
please dont croupt my ass
Your script should be fine, but if you haven't saved recently that might sting
corrupt*
i havent clicked save in li ke 2 years
at least i have prefabs of everything
because my projcet got deleted multiple times and didnt remove scripts so i should be good
yup this place is fucking empty
like some ground and a bean
Check to make sure the scene was loaded
It might have loaded the default scene instead of your scene when it restarted
otherwise bad news bears
nope but prefabs π
I religiously pres ctrl-s now'a days because of specifically while loops π π
Lol man ima make ctrl s my secondly routine :)
im a autosaver
bro comeon i forgot to edit the code and now unity freezed again
π
π
but i saved like two seconds ago so i mgood
I wan't to say if you code long enough you stop doing that as well, but...
It is like there is just enough time for you to forget why it crashed for you to reflexively press that play button again
man i cant belive its been almost two years since i started coding but the stops made me forget everything that two years are like 1 month learning
I have been doing this for twelve and I constantly am having to re learn things. Like my computer science teach said on my final. "use google, because you will be using it for the rest of your career."
bro when i put if it just does it for one frame
Ah
I am assuming state is being changed
Check in
MyInput();
SpeedControl();
StateHandler();
FovBooster();
StateSpam();
Dashing();
if state is being change
private void Update()
{
// ground check
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.3f, whatIsGround);
ClimbAble = Physics.Raycast(transform.position, new Vector3(1, 0, 1), playerHeight * .5f + .3f, whatIsGround);
ClimbAbleMinus = Physics.Raycast(transform.position, new Vector3(0, 0, -1), playerHeight * .5f + .3f, whatIsGround);
MyInput();
SpeedControl();
StateHandler();
FovBooster();
StateSpam();
Dashing();
Climbing();
if(state == MovementState.climbing)
{
ClimbAble = false;
}
// handle drag
if (grounded)
rb.drag = groundDrag;
else
rb.drag = 0;
}```
maybe wrap those in an if like if(state != MovementState.climbing)
i want climbable to be off when im climbing bro what
put that if before the Climbing();
we are setting climb able false after we are climbing
still doesnt work
Okay one sec
private void Update()
{
// ground check
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.3f, whatIsGround);
ClimbAble = Physics.Raycast(transform.position, new Vector3(1, 0, 1), playerHeight * .5f + .3f, whatIsGround);
ClimbAbleMinus = Physics.Raycast(transform.position, new Vector3(0, 0, -1), playerHeight * .5f + .3f, whatIsGround);
if(state != MovementState.climbing)
{
MyInput();
SpeedControl();
StateHandler();
FovBooster();
StateSpam();
Dashing();
}
if(state == MovementState.climbing)
{
ClimbAble = false;
}
Climbing();
// handle drag
if (grounded)
rb.drag = groundDrag;
else
rb.drag = 0;
}
oh nvm i dont :)
Oh well that sounds promising
oh XD
hats what i did
that*
I also added the state != climbing check for all the others.
the only reason ClimbAble should be true is if for some reason the state is changing to something else.
is probably will cause some other issues, but hopefully will make climbing work
yeah
that is the other issues it would cause lol
easily fixed though
So what we want is just to switch out the climbAble and CanClimb
basically the raycast will say if there is something to climb, and we will add some logic to a new bool that says if the play can climb
so i mkake a new bool
yep
so change
if (Input.GetKey(climbKey) && ClimbAble == true && CanClimb)
{
CanClimb = false;
and
if(!CanClimb)
{
ClimbAble = false;
}
also get rid of the if around the other method calls.
the if(state != MovementState.climbing)
Last we need to change the coroutine, so one sec
ok bu t ima go to the restroom
okay
IEnumerator ClimbingDelay()
{
yield return new WaitForSeconds(5f);
if (state != MovementState.air && state != MovementState.climbing)
{
CanClimb = true;
}
else
{
StartCoroutine(ClimbingDelay());
}
}
backkers
so i put this inseated of our old one?
yes
did you do the three above also?
yea
then yeah give it a shot
now it doesnt even turn on climbable
meaning something is holding it always from turning on
climbed or not
Is CanClimb being set to true
no
Like bool CanClimb = true;
yeah just add the = true; to CanClimb
when?
just where it is declared
meaning the raycast
but something is preventing the bool from turning on no matter what soever
bool CanClimb = true;
in update?
no, uhm,,,
yea
not at all
okay
theres something prevnting it
where you created CanClimb as a varaible
yea
add the = true; and then in the editor in edit mode you might have to set it true once also
you can set a default value to variables, but if it is public the editor might not update it automatically
ok trsut me it wont work cuz something is prevnting it
are you in play mode?
no
if(state != MovementState.climbing)
{
MyInput();
SpeedControl();
StateHandler();
FovBooster();
StateSpam();
Dashing();
}
if(state == MovementState.climbing)
{
ClimbAble = false;
}
change that to
MyInput();
SpeedControl();
StateHandler();
FovBooster();
StateSpam();
Dashing();
if(!CanClimb)
{
ClimbAble = false;
}
aight
Also change
did
IEnumerator ClimbingDelay()
{
yield return new WaitForSeconds(5f);
if (state != MovementState.air && state != MovementState.climbing)
{
CanClimb = true;
ClimbAble = true;
}
else
{
StartCoroutine(ClimbingDelay());
}
}
private void Climbing()
{
if (Input.GetKey(climbKey) && ClimbAble == true && CanClimb)
{
ClimbAble =false;
rb.AddForce(0, climbDistance, 0, ForceMode.Impulse);
Debug.Log("Climbed");
state = MovementState.climbing;
}
if(!CanClimb) {
ClimbAble = false;
}
// Invoke(nameof(readyToClimbNow), climbingCooldown);
// StartCoroutine(ClimbingDelay());
}
to
IEnumerator ClimbingDelay()
{
yield return new WaitForSeconds(5f);
if (state != MovementState.air && state != MovementState.climbing)
{
CanClimb = true;
}
else
{
StartCoroutine(ClimbingDelay());
}
}
private void Climbing()
{
if (Input.GetKey(climbKey) && ClimbAble == true && CanClimb)
{
CanClimb =false;
rb.AddForce(0, climbDistance, 0, ForceMode.Impulse);
StartCoroutine(ClimbingDelay());
Debug.Log("Climbed");
state = MovementState.climbing;
}
// Invoke(nameof(readyToClimbNow), climbingCooldown);
// StartCoroutine(ClimbingDelay());
}
wait
sorry
aight
Sorry, I am getting tired
its ok
I will look through the rest of the code real quick
youve helped for like and hour nothing to be sorry about
im the person who should be sorry for putting you in this
See if there is anything else that might be causing an issue
no worries really
I love coding
aight
well and hate it
yeah, if CanClimb is not set to true, that will constantly be happening
aaaah
So while not in play mode, make sure CanClimb is true in editor
and then play and it should be okay
hopefully
you know
LOL
cool
wait where is that code.
update duh
just got back to a computer so have VS
sui
Yeah, I mean if you need to go back your last version is just above
ok
This logic is a little backwards now that I am looking at it on a bigger screen, but lets see if it works first.
Ah I see one thing
not even climbable ture
Add
Debug.Log(CanClimb); before our if in update
I am not sure why it would be false, but that should be the only thing stopping us from climbing at all
bro
agian
if (!CanClimb) {
ClimbAble = false;
}```
this code is the preventing
litteraly breaking the climb in 3 lines
canclimb cant be on if climeable is never on
you should be able to get rid of it
and?
no I mean is it working lol
uhg
is there a delay for from the initial climb and flying?
or is it just straight up?
no
ijust hold v and fly
and if i spam v like v v v v v v v v v v v v vv v v v itll fly me
did you just rid of that or did you add something else?
i made !canclimb climbable and climbable to canclimb = true;
if (ClimbAble == true) {
CanClimb = true;
}```
okay try it with out that also
okay, post the full code again. I can't track what is happening if multiple changes are being made.
otherwise we both might just need sleep/rest at this point lol
if (state == MovementState.climbing) {
CanClimb = false;
}
if (ClimbAble == true) {
CanClimb = true;
}
i did that already :>
get rid of them?
yeah, get rid of it.
oh
both, and try
lets see
it says climbable is true but v doesnt do no nothing
be right back
ima go for like 10
Send a screen grab of the script in the editor when you get back.