#Game Help
1 messages · Page 2 of 1
like when you start the game, you will automatically be in the horizontal movement state?
so, like, you can move left and right from the start
no no i mean
when you start the game, you're automatically set to horizontal state
because as of now, your first state is jump.
maybe if I rearranged the order?
Ah, you mean the current state? Yes, I guess you can set it in Start for now.
so what would i do for that?
Assign it.
yeah i'm having trouble with that
like i know it ain't this
or do i use changestate
which, we still haven't done anything in changestate
No it's not. What is the variable that we use for current state?
ok. should we continue this tomorrow?
or my tomorrow anyways?
or... you know what i mean
I will be replying when I have time. Try implementing the logic for the rest of the states for now.
ok
thank you
i'll show you what i have so far tomorrow when you're ready same time as today
@sterile socket I feel like using a raycast for the ground detection may not be the best idea
I personally use Physics2D.OverlapCircle()
Won't it fit more for this game?
It might be better, yes, but it's a minor refactor that they can do later, when the core features work.
Yeah but in a game with mechanics such as climbing it might be better for the ground detection to have a radius rather than a single line
That what I was using before
But, I mean, it works for now. And if it doesn’t work later, I can change it to that. But so far, I do have the climbing state working almost perfectly
Alright
@sterile socket @flat nymph @orchid matrix Hello! I'm gonna have to start a little later tonight but, I mean, it shouldn't really affect much. I'll still be around usually the time you are. So anyways, here's what I got done last night. I basically added the rest of the stuff from the updatestate method dlich told me to add. It's not perfect by any means, but it's a nice start. I also listed the issues the code has so far in the progress report in the script at the top. https://gdl.space/cohaculose.cs
But anyways check the code when anyone is available, I’ll be back probably in a few hours right around the time you should be available to see. Thanks!
Why is your state machine throwing the commands to do something. It should be mainly for catching inputs, then swtiching to another state
hmm.. Anyways, I havent really read what you were discussing yesterday with dlich, maybe we can just wait for him again to review your code.
Is that code working so far?
I mean, aside from the issues I put in the report yeah
Switching states woulda been changestate() right? Again I guess we’re gonna have to wait for dlich
@sterile socket @orchid matrix hey guys! I'm back! Do you wanna get started?
so yes, definitely gonna need to work on the gravity for stuff like jumping, knockback and a little bit for the climbing too because that isn't perfect either.
I'm a bit busy now. I will be able to have a look in 30min-hour
aight understandable. see ya then
@sterile socket you ready?
- We want to update the state at the very end of update after
ChangeStatehas been called so that we update the correct state. - All the state changes should be processed in
ChangeState(). HurtorAttackare not great names for components. Which might suggest that what they do should be included in this script perhaps. Then, this script should be renamed as well. MaybeCharacterController2Dor something.- There are some namespaces that you don't need in the usings. One of them would prevent you from building the game.
- Since we move all the change state logic to
ChangeState(),OnTriggerEnter2Dshouldn't set the state as well. Instead make a separate booloverlappingWithLadder(or smth) and set it to true/false when entering/exiting the ladder trigger. - Jump and knockback issues can be addressed after you implemented the change state logic. Basically, you need additional state for falling down.
for 3 and 4, Hurt and Attack are calling different scripts. I don't want this script to be more cluttered than it already is. What namespaces should i get rid of?
This script is not cluttered. There are cases when you can split the functionality into multiple scripts, but not when it's tightly coupled with the logic in this script. Ask yourself this question: will something break if that other component is not assigned? If yes, then it shouldn't be a separate script or the logic needs to be changed such that current component works even when the other one does not exist.
Anyways, regardless of what you do, Hurt is a very bad naming from the OOP perspective as it describes an action and not an object. At least rename it as HitDetector or something.
alright. want me to rename the scripts then?
As for the namespaces, your ide should tell you what namespaces are redundant
You can keep it as it is for now. Might consider doing that refactoring later if it ever comes to that. Get it working first.
alright. how's this looking so far? for falling method, what should the parameters be? specifically for y?https://gdl.space/nagiweleze.cs
think maybe a float called "fallingSpeed" or something?
Hello?
When you share updated code, can you give an overview of the changes?
oh yeah. i move all the state changes into changestate(), renamed the code, renamed the other scripts, added a bool for colliding with the steps, and moved the updatestate call in update like you asked. oh and got rid of the uneccesary break
oh and added a falling state, but don't know what to put for falling
i move all the state changes into changestate()
I don't see anything like that at all.
You still have the logic of state changing in your Update:
if (Input.GetKeyDown(KeyCode.Space))
{
if (isGrounded == true)
{
state = MovementState.Jump;
}
}
if (hurt.isHurt == true)
{
}
if (Input.GetKey(KeyCode.DownArrow))
{
animator.SetBool("isCrouching", true);
state = MovementState.Crouch;
}
And some other places:
if (hit.collider.gameObject.CompareTag("Ground"))
{
isGrounded = true;
}
And ChangeState doesn't change the state at all. It sets the same state as it is already in which is totally pointless.
case MovementState.Jump:
state = MovementState.Jump;
break;
case MovementState.Crouch:
state = MovementState.Crouch;
break;
case MovementState.Knockback:
state = MovementState.Knockback;
break;
case MovementState.Climb:
state = MovementState.Climb;
break;
case MovementState.Falling:
state = MovementState.Falling;
break;
oh. I'm confused then
let's focus on one thing at a time i guess. let's start with the falling state, ig.
and isGrounded isn't a state. it's a bool.
your changestate() actually just need one thing to change to be functional at least
or to add
Ah, right. Then you can ignore that part. But the other is still relevant. And you should get it done before dealing with the falling state.
Well, what else do you expect it to do? Judging from it's name...
anyways, I think you dont need a changestate method in your game, just change the state direfctly in code lines
oh, that's because i forgot to get rid of those logic of changing states. i did
dlich wdyt?
No, Change state would make things easier to read and debug.
ok
Besides, we might want to handle things like entering and exiting a new state later on, which ChangeState would be useful for.
alright. so... do you wanna focus on falling now?
just as long as he fix how he is using that, im in haha
u got it
implement your change state logic.
do that first?
besides, there's not much to fix in the falling state, you just need to figure out what vector to return.
yeah
then i guess let's focus on changestate first
so we want change state to change the state you're in
Yes.
ok. so that's the part i'm having the most difficulty with
Do you remember that in your pseudocode you had CAN *DO SOMETHING* thing?
yes
well, that's where you can use that logic.
so like
if (state != this || state != that)?
go through the state in the ChangeState and see what states you can transition to from your current state.
You don't need that. You have a switch block.
All you need is to put the correct conditions in the right case and change state if they're satisfied.
ok. so for horizontal movement, you're not jumping, you're not attacking, and you're not croucing, and you're not climbing, and you're not hurt
oh! first thing's first
what type is changestate()? is it a vector2 like updatestate?
i guess not because all we're doing is changing the state you're in
You might want it to return bool in the future perhaps, but it's fine as it is for now.
you can actually use any type, as long as you are returning the right type
then make it a bool?
aight
imagine void as the pawn in a chess
horizontalmovement. i guess my main issue isn't idk what you mean when you say put in the conditions, but how to word it
like how to code that
if you promote it, it have to stay as that
cause you said it's not just
if this is true
so void is perfect if a function dont need to return any value in the moment
Think like that:
-What states is it possible to change to from the current state?
-What conditions need to be satisfied in order for that change to happen?
so for horizontal, it's possible to change to pretty much any state ig
and they depend on stuff like if i'm pressing jump or crouch or getting hit or if the climbing bool is correct
Right, then add all the conditions and change to the correct state
Is it possible to change to a falling state from horizontal movement though?
no
no midair control
until you hit the ground
i know this isn't right but can you tell me what i'm doing wrong?
Do you understand how switch statements work?
Okay. So what is state equal to when you're in this case?
horizontal movement
then why would you need addition checks?
idk
Why did you type what you did?
idk you told me to put in all the conditions you can change to horizontal movement
By conditions, I mean all the other things beside the current state
so put in... all the states you can change to horizontal movement
put not horizontal movement
That's the point of the state machine: it narrows down the conditions you need to make for your logic, because you know what state you're in and only need to make checks relevant to that state.
Not sure what you mean by that.
state = movementstate.jump and so forth
not right tho
so idk
Yes
Yes, changing state is what we're doing there, no?
yes.
like this?
so then that doesn't seem to make sense. could you explain it to me a bit
so i'm putting in the states. the machine looks at all these states. and then... what?
Because it doesn't
i did it wrong
Let's pretend you're the CPU again. Go through your ChangeState method line by line and describe what happens. Let's assume that state is HorizontalMovement when you start.
Before that.
What is the purpose of ChangeState method?
Yep. Now step through the code.
Okay
not right, i guess?
cause i was thinking, you told me to put in all the conditions that would cause the state to change
Not wrong
I was just wondering if that's the only condition you need. But perhaps it is.
Complete it for the rest of the states and test.
oh shit. isgrounded you're right
Yes, but on the other hand, can you be in the HorizontalMovement state while not grounded?
no
Then there's no need to check it.
In fact, if you were, then there's probably a bug somewhere else.
if i were what?
If you were not grounded in the horizontal movement state, then there is probably a bug somewhere else in your code.
well, test it out.
Good. Now to the same for the rest of the cases.
so for jump, how would i switch from that to horizontal movement? if i landed?
here's the tricky part for jump. i can jump horizontally, but no midair control. can i horizontal move in the jump state?
Well, what does your jump state do?
jump
Perhaps horizontal movement was not the best name for that state. Maybe grounded Movement would have been better.
true but i ain't gonna change it
That's too abstract. What exactly is jump in your game?
What does the state do?
you... move up in the air... then fall down
is falling down really part of the jumping?
no
So it's not part of the jump state
it's it's own state
Then what does jump state do again?
move up
Okay. Does it move up indefinitely?
no
Then describe what that state actually does(including how long or under what condition)
if you're on the ground, you move up in the air for, like, a half second, then change to the fall state
So there's a a time constraint? Or maybe distance constraint?
Let's assume it's time
Then what would be the condition to change from jumping to falling?
when you reach a certain time
more precisely, "when certain time has passed since jumping(entering the jump state)"
yeh
so when in the jump state... countdown to a certain time, then switch to the fall state
and you can't do anything else when jumping so i guess do that
What do you think that does?
uses the coroutine to countdown and then change to the falling state
Turn into a CPU for a moment and step through the lines in this case, what happens line by line?
startcoroutine. go to the coroutine i made (jumpCountdown)
then go to the falling state. set the state to the result of that
yeah
So you basically transition to the Falling state immediately
Well, that's one option yeah. But there's another problem.
Let's say it's the second frame of being in the Jumping state, what happens then?
you're... still jumping?
Code wise. When it runs through the ChangeState method
oh
So every frame of the jump state, you start one more coroutine
That can't lead to anything good
yeah
what if... no coroutine... but...idk a for loop?
but i guess that wouldn't work either
let's hear that though? for loop what? And why do you think that it's not gonna work?
so we make a variable, have a for loop that either subtracts or adds to that variable until it reaches a certain value, then you switch to falling
but like the coroutine, every frame, it's just gonna cause the for loop to repeat
Well, yeah. More importantly, for loop is gonna loop through all the iterations before moving to the next line of code. Code is executed one line at a time. while your loop is being executed, the whole engine is frozen. That's why if you were to do something like wait actual real time in that loop, it would've frozen your game entirely for a certain period.
yes.
The issue is essentially in the fact that we want to execute some code only once when entering a state, right?
yes
That's where another essential part of the state machine can be helpful. When we change state, we could implement an EnterState and ExitState functions that would be called precisely once, when we enter/exit a state.
oh. so... make two new methods called enterstate and exitstate?
So far, we don't have much use for ExitState, so start from implementing EnterState
more methods... greeeeat 🤣
Ideally, it would've been several separate classes, but your state machine is simple enough to have it hardcoded in one script
so what type would it be? just void?
but it couldn't, right? it needs to return something right?
return the state you're changing to?
Why? Don't we already now what state we're changing to?
i guess what the type is
You're thinking from the wrong end.
A method type is dictated by what we want it to return.
What do you want the EnterStateMethod to return?
the state?
to enter the state
Well, that's not wrong, but why did we make it in the first place?
so you only enter it once
We already enter the state once
Think. What was the issue that we were trying to solve
the starting a new coroutine over and over
Basically, the same code executing more than once, right?
yes
Taking that into account, what is the purpose of EnterState method?
only running it once
It would be wise to have a switch inside as well so that we can reuse it for all the states
ohhh so true
And in each of the cases you add code that you only want to be executed once when you enter that state.
Perhaps. What does your JumpCountdown look like?
That does nothing at all
oh
What was it that you wanted to do after the countdown
yes
Ok
vectors. i'm thinking what should y be?
What do we use that vector for?
physics
physics?
And what does that do?
Right. What kind of velocity do we want when falling?
negative
Well, that's not wrong.
But thinking from real life physics perspective, how would you calculate a falling object velocity?
time * acceleration
and what is acceleration equal to?
that IS the acceleration of gravity
To sum it up, when an object is falling, it only has gravity force acting on it.
So, how would the velocity change between frames when falling?
it gets faster
Write it as an equation
velocity = gravity * time
That's if you calculate the velocity disregarding the current velocity
I mean isn't it very simple? You just want to add up to the current velocity
velocity = currentVelocity + gravity * time since last frame.
yeah.
Current velocity is the same variable, in code that would look like this:
velocity = velocity + gravity * deltaTime;
Or even simpler:
velocity += gravity * deltaTime;
However
so... y would be rgdb.velocity.y + gravityScale * deltaTime?
What about the x part then?
MovementSpeed?
Yes. Although, velocity of your x doesn't sound like the correct way to say it.
Anyways, since both x and y use your current velocity, you can expand that expression.
Instead of creating a new vector, you can add the additional velocity vector instead, like I did here:
velocity += gravity * deltaTime;
so is this right?
Yes, but let's rewrite it as I suggested to make it cleaner.
so no vector?
remind me
This is what you have now:
Va = new Vector2(Vb.x + Vc.x, Vb.y + Vc.y);
It's the same as this:
Va = Vb + Vc;
Which one reads better?
First of all, you don't need to assign it here. You return the result instead.
If you do want to assign it to a new vector first, then do that before returning.
And second, gravity needs to be represented as a vector.
if it's all the same to you, i'd prefer to use the first one i did
the one you said was right
I'd prefer that you learned something from that, but okay...
That being said, it's not exactly right.
oh it's not?
Well, it would have been if you were controlling the object movement entirely by yourself.
But since you're using a dynamic rb, unity physics would apply forces to it as well
Like gravity
In fact, the value of velocity already includes the calculation of gravity on that frame
So, what do you need to return?
yes
oh fuck, i was just taking a shot in the dark XD
so anyways how would we do that?
Well, if physics system already does everything you need for you, do you need to modify the velocity?
no
Which means..?
where did that came from?
Why not?
cause it's alrady doing the velocity
It is, but what are we doing with the returned value?
adding it to the velocity of rgbd
where are we adding it?
what line?
Where we "add" it
This is not "addition", is it?
bingo
it does?
Ah, I thought that was response to a different question...
No. It doesn't need to be changed
ok
But if it's not "addition", then what is it?
setting
Yep
so we're setting the velocity
So we are setting the returned value
yes
Yes. Taking that into account, if physics system already calculates everything for us, what value do we need to set?
the x and y
?
in the vector
Do we need to change the velocity in any way?
no
gravity?
Why..?
What does y need to be in order for x value to remain unchanged?
var x = some value;
var y = ?
x = y;
0
hey hey. That's serious math issues there...
... rgbdvelocity.x?
How is that related to my question?
Ok. Go through this line by line with your answer and see what value x has in the end.
var x = some value;
var y = ?
x = y;
variables
You can't change x. Only y
Yes. It has some value. You don't know what it is
so we don't want x to change... unless i'm jumping while moving then it changes but you just can't control yourself in midair
the value will... make it so x doesn't change
Forget about your game for a moment. Solve the equation above.
if you want, we can rephrase it like this:
var x = c;
var y = ?
x = y;
x = y * c?
no. I'm not asking you to solve for x. I'm asking you what would you put in place of ?
c?
Yes. But let's say you can't use c there.
y = x?
that
in the end you need to assign x to itself for it to not change.
Now going back to what we need to assign to velocity if we don't want it to change
itself?
So, what do we need to return from the falling state?
so just return rgbd.velocity
Yes
ok
here's my new problem
i can jump, yes
but i can't move forward when jumping while moving
Share the jumping state update code
This is the general state update method. where do you update the jump state?
what is air speed and movementspeed?
airspeed is the movement of your character while jumping
Where do you set it?
What value?
and MovementSpeed?
3
It should be doing something indeed.
but it ain't
Are you just moving vertically then?
Okay. Here's where the current approach is good for debugging.
instead of assigning the velocity to an rb directly, assign it to a public/serailized variable.
then assign that variable to the rb velocity.
With this you'll be able to see the value in the inspector.
No. I already mentioned where you need to assign it.
You should know it by now. We've been dealing with it the whole day today.
yeah
where?
but i did?
Did what?
here?
pay attention to the word "instead". It's very important
There should only be one place in your code where you assign rb velocity. So when I say "instead" it can only be that place.
when you say "place" you mean place in the script?
yes
or, like, place in a variable?
then i'm sorry, but idk where to put it
Where do we assign rb velocity?
in awake
since when..?
Yes
so... we make... a variable there
we assign the variable there
because that's only half of what I told you to do
sure they are
You still want the rb velocity to be assigned properly as before, right?
yes
and you also want the velocity variable to be updated, right?
Well, that'll do
- There's an issue with EnterState(or rather where you're calling it). We didn't finish with it yet. But That's probably not the cause of the issue.
Can you confirm, that when you're falling, the active state is actually "falling"?
aah
yeh
Wait. Nvm. The issue is with the Jump state, right?
ig
you're so right
it work... but...
you only go right
when i press space and left, i still go right
Yep. Do you understand why?
because i'm always setting it to a positive number
Yes. To be precise, because you're always setting it to the same number
What you want is it to be affected by the velocity when you started the jump, right?
Then you just need to remember velocity x at the start of the jump and use that
Or rather
you just leave the x velocity unchanged during jump
nope
Then remove it
i did
hmmm. when i press jump and direction, they don't move as far as when i'm moving and jumping
what if i multiply by airspeed?
dunno if that'll work
I guess it's because input doesn't go to 1 right away, so your velocity is increasing over some time
Wait, you're not using axis...
can we... have you go max velocity right away?
cause you really only just going one speed
Or do you? What's InputHandler?
Ah, GetAxisRaw does return discreet values. So the problem is somewhere else.
just GetAxis
Change it to Raw
ok
didn't do anything lol
y'know what? it's fine as is ig
anyways i assume same for knockback except just going to opposite direction?
or maybe make a different variable for knockback so you're always getting knockbacked the same distance?
Then perhaps cache the input at the start of the jump and calculate x velocity from it.
You probably want the direction to be from the enemy towards your character. But aside from that yes.
It could also be due to drag/dumping params of your rb.
ehhh cross that bridge when we get there
dlich imma be real with you
it's 2:30 in the morning and im tired af
can we continue this another night?
Yes. You could continue on your own when you have time. It's really just assigning the correct velocity in different states now. Refer to your previous code where needed. If you face any issues, try solving them on your own first. If nothing works, come back and share the updated code.
There's still the EnterState that doesn't work correctly now, so I guess I could help with that.
okay. if i don't have time tomorrow, i'll continue working on it probably monday. thanks for your help. if i have any issues i'll let you and the others here know
@sterile socket @orchid matrix hey! so I made a change to checking for ground. for the falling state, the isgrounded method didn't work because it would automatically switch to horizontal movement state even in the air. so i changed it from a raycast to overlapcircle like i did in my previous script. problem here is that it works fine when i jump, but for knockback, for some reason, i won't switch back to horizontal movement when i land. I'll post the script here. But could anyone explain what's wrong here? https://gdl.space/bahobalawi.cs
So what state does it stay in?
Falling?
knockback
er nevermind yes falling
Okay. Think then. What's condition to change from falling to horizontal movement?
if isgrounded() == true
So that would mean that this condition is not satisfied, right?
Or that we change to the falling state again immediately.
Here's how you can debug it:
Add a previousState variable of type MovementState in your ChangeEtate method and ssign it the state value.
At the bottom of the method check if previousState is equal to state, and if not Debug log the new current state.
gimme a sec. i'm working out this bug when i'm touching the ground even if i'm not on the ground
specifically if i'm, like, walking off a platform
think i solved it
Sorry, can you rephrase it? If you're walking off the platform what happens? And especially, what states changes happen?
if i walk off the platform, it still says i'm touching the ground. i think its because the overlap circle radius is too big
so i made it smaller. seems to work now
anyways so make a previousstate for movementstate and check to see if it equals state
like this? I'm getting an error thohttps://gdl.space/rixeronoli.cpp
What error?
Ah, well, you didn't clean your namespaces as I suggested before, did you..?
Is there any specific reason you need System.Diagnostics in your script?
The "using" statement.
gotcha! i was looking at the wrong script lol
okay so basically it's saying i'm switching between knockback and horizontalmovement constantly
you think it might have something to do with my hitdetector script?
Possibly. What are the conditions for switching between these 2 states?
do you want me to show you my hit detector script?
No. I want you to think and figure it out on your own. Or at least make an effort to.
Feel free to share your thinking process of solving the issue and might give feedback on it.
ok
figured it out
i think
okay yeah it works. just gotta, like, add invincibility frames to my character and it's golden
also an animation issue, you don't switch back to your idle state, but i think i can fix that later
@sterile socket I think I got the majority of it down (say for some animation issue). there are a couple of bugs, but the one i really wanna focus on is the physics for climbing steps
i mentioned it's kinda wonky
Describe the issue and share the updated code
ehh it's kinda hard to describe but going down the steps is weird
like, you can't really go down them, but you don't go up either if i press down. you just, sorta... either not move or just float slowly down
here you gohttps://gdl.space/gefawiqomo.cs
Did you confirm that the same state is active during that time?
odd... sometimes you don't even switch to climbing state at all
From what state?
horizontalmovement
If that's really what's happening, then there's only one possible explanation. isOverlapWithLadder is not being set to true.
I think the issue is in your OnTriggerEnter2D
if (collision.gameObject.CompareTag("Ladder"))
{
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow))
{
isOverlapWithLadder = true;
}
}
Is there a guarantee that one of the inputs is true during the physics update when you first start colliding with the ladder?
i think i got it to work
if anything happens, i'll let you know
but basically what i did was use an overlap circle instead of on trigger
cause i was thinking: my character doesn't have a trigger
That's not relevant. I mean, it did work sometimes, did it not?
The reason is most likely what I pointed out previously.
You solution fixes it too, because you probably do the overlap check in regular update.
hmmm actually now that you think about it
i think something else is triggering my being able to go up steps
cause i'm still always in horizontal movement even when i go up steps
and i even untagged the change from horizontal to climb in changestate and it still works
only difference is i don't have the bug anymore
i wonder if that's a glitch in unity's part
lemme restart unity
No. There's no such "glitches" on the unity part.
there's clearly an issue with your logic.
If it works perfectly fine, then there is no issue, is there?
no i guess not
hold on...
ah. unity didn't save the update for changing the stepscheck
odd
except oh wait it did
except now I'm facing the same issues again
so this was a lie 🤣
it WAS just a glitch LMAO I'M DEAD
I'm not sure I even understand what was it that you called a "glitch"
like just Unity acting weird
that doesn't explain anything
idk how else to describe it. I close unity. i open it back up. everything in the code is the same, but now the issues i had are back
What issues??
this
None of what you're saying now makes any sense. You said that it got fixed after restarting unity. But now you're saying the opposite thing..?
no i said i got it fixed, then i restarted unity, now it's not fixed
Then why did you restart unity if there was no issue?
because i wanted to see if the "fix" was really just because i'm a coding genius or just unity acting up LOL
So the conclusion is?
and turns out it was the second
it was just unity acting up
so we're back to square one
Unity "acting up" fixed your issue before the restart?
yes
That doesn't make sense, but ok.
i know it doesn't but that's my only explanation
So what's the issue that is left?
basically you can't go down steps and if you try to mid-climbing, you just float slowly down
and you also don't switch to climbing state
Share the updated code
How are you able to climb then?
What calling what?
What do you see in your console about state changes? Or in your inspector, what is the current during climbing?
okay this is weird
now I CAN change to climb state
lemme restart unity to see if this is also unity acting weird
so you can climb
but new problem time
Unity doesn't act up weird...😅
don't go back to "horizontalmovement" when touching ground
or i mean... platform
cause, like, i climb up steps, usually i'll land on the platform, but now... i just keep climbing
i don't go back to horizontal state
i wanna say it's a hitbox thing
What is the condition for switching to a horizontal state from climbing?
nah nah more than likely it's hitbox related
cause if i climb back to the ground, it'll switch back
The most important problem with your thinking is that you jump to conclusions.
oh
There's always a certain chain of logic that you can follow from the issue occurring to it's cause.
If you don't check each link in the chain, you might miss the cause. By trying to fix something that is not the cause, you might introduce more bugs
i get that
what do you think the problem is?
lemme try overlap circle again
okay so... i check debug
apparently, i'm switching to climb and then immediately switching to horizontal movement
i mean, it works... but now when i reach the platform on top the steps, i fall through it lol
but y'know what? THAT is a hitbox issue cause i tested repositioning the platform and it worked
Okay so I restarted unity, I even restarted my computer, unplugged my flash drive (safely), plugged it back in, and opened unity
Safe to say it’s not messing around anymore and this issue… somehow… resolved itself
I have no idea why, it doesn’t make any sense, Dunno how long it’ll last, but bugger all I’m not gonna complain 🤣
Think I figured out what the problem is
Or was
I am climbing. It does set me to the climbing state, but then immediately switches to horizontal movement. Which means if I were to, like, comment out the climb logic in changestate, I’ll have the same issues I mentioned about not being able to climb down
I’m HOPING that’s the problem. Because that seems like it
Didn't you say before that it doesn't change to climbing state at all?
I said that but because I didn’t check debug
It does but only for, like, a split second
Ok, so I guess the real issue is that your debugging is incorrect. You don't consider all the available information or you misinterpret it. Making you draw wrong conclusions.
If that is really what is happening, then it should be easy to fix. Figure out why it changes between these states and eliminate the cause
Well I showed you my debugging script, yes?
debugging script?
Yeah. There's no problem with it.
Although it could've been more verbose to make it easier to understand the situation
for example, you could print something like transitioning from *previousState* to *currentState*
What I meant though, is that you did not look at the console at all or did not interpret the logs correctly.
Yknow what it could be?
Since the condition for changing from climb to horizontal is if I’m on the ground, and when I touch the ladder, I’m on the ground
This happened with jump too
There's only one way climbing -> horizontal movement transition can happen.
Investigate why it happens and you'll be able to fix it.
Okay, that's good thinking.
So we gotta figure out how to make it so you climb, keep climbing, and when you get to your destination, THEN you go back to horizontal movement
Cause, like, if I switch to climb, what’ll happen is even if I’m touching the platform on top the steps, I still keep climbing
Logically thinking about the correct behavior, is just touching the ladder means that you're climbing?
No, also when you press up or down
Ohhhh!
But then, wait, what if I’m still pressing up when I reach the top? I’ll still climb
Even if I hit the ground, I’ll climb in the air
Are you still touching the ladder, when you "climb in the air"?
No
So, there's another case where you want to transition out of the climbing state, right?
Yeah
So I make another state called DoneClimbing?
Set it for when I’m not touching the steps?
No
another case where you want to transition out of the climbing state
Means that there is another condition that could lead to state change
Ohhh. Like “if isClimbing == false”
IsClimbing being the overlap circle
I’m not touching the ladder
yes
isn't it logical? If you're not touching the ladder, what are you supposed to climb?
True
I mean I just added that to the script and now I have no bugs whatsoever
Cause, like, at first, I had a bug where if you climb then exit out of climbing then immediately go back to climbing you’ll be permanently stuck in the climb state
But I don’t have that issue anymore now that I added that condition
But I know that’s not the issue here. The issue is switching to climbing state.
Then that's just another different bug
Yeah
-analyze what's happening
-why it is happening
-confirm with available information. Output more debug information if necessary
-once's you know what the cause, think of what solution would fix it without causing new bugs
Hmmm well we know
-I’m immediately switching from climb to horizontal
-we know this through the debugging
-it’s more than likely cause of the groundcheck condition
-gotta figure out how to make it so that you can continue to stay in the climbing state until you are no longer touching the steps
-I’m immediately switching from climb to horizontal
This basically means, that the current condition is to weak, it's satisfied in situations even when you don't want to change the state.
Figure out what's the additional condition needs to be.
Well I thought it would be (&& isClimbingSteps false) (the overlap circle) but that ain’t it either
why not?
what's the logic behind it though?
just testing is not enough
you need to understand why
maybe there's a fault with your testing
how can you know that without understanding the cause?
Or maybe there's an additional factor that affected the testing. Either way you wouldn't understand from just testing.
That’s… new
But okay let’s see
If I’m grounded and I’m not touching the steps and not pressing up and down, that means I’m not going up the steps
If I DO do those things, I am climbing the steps
According to your logic, that should be there, no?
What nothing?
I mean it didn’t work
So what's the current issue again?
Well technically none, but it’s just not switching to climbing state
Or it is, but then immediately back to horizontal movement
That sounds like an issue
Which one?
Second one
And what are the conditions of switching from climbing to horizontal now?
So, if you're on the ground or not overlapping with a ladder
Yes
Is that enough?
Probably not
You know what is weird tho?
If I change the || to &&, or just get rid of that second condition altogether…
If I go up the steps and then midway stop climbing and then climb again, THEN it switches to climbing state
These are 2 separate changes. Analyze them one by one.
Start with changing to &&
Yes.
So if I’m touching the ground AND not touching the steps
Yea
Which is… not what I want?
You don't want that?
I mean I guess I do but, it doesn’t work
What doesn't work?
The climbing
I still go to horizontal
Only difference is if I let go of the arrow keys and then press them again midnclimb, then it switches to climb state
Which means that one of the conditions doesn't return the value that you expect.
And I keep climbing even if I’m not touching the ladder
…it can’t be the groundcheck could it?
If you suspect one of the conditions, just debug them.
Make sure you always know what values they have.
I don’t know
Look, man…
Okay
Dlich can I be honest with you?
It’s running perfectly fine. I have no issues going up the steps. And tbh, if it were to be set to climb state, it’d have numerous glitches in it like continuing to climb in the air. Plus, it’s going on 2 in the morning here. I think I might just look back into it later and move on with stuff like animations and maybe tuning out some minor glitches. Thank you for your help tonight. If I need any help, I’ll let you and the others know. But for now, I might need to stop for the night.
I'm sorry.
I mean, you shouldn't be saying that to me. It's your project. I don't really care whether it's working or not. I'm here only to help you learn something about game dev.
Yeah I know. Again I’m not giving up on it. I’m just takin a break for the night.
It's not like your reply time matters, so you don't need to say that every time. Just reply when you can. That's the same for me.
Ok
Idk, I just feel bad because I know I should know this stuff but then I get to actually programming and it’s hard to problem solve for me. Maybe I just need some more practice and learning, and who knows? Maybe after this game is done, I can practice some more. Make some more smaller games, get better at it. I just feel like my progress on learning this stuff is very slow.
Yeah, I think that's what college does to you. Instead of actually pursuing learning, you aim for the grades and finishing it off. In the end, even if you did get something into your head temporarily, your brain just discards it as not important later, when you have to move to another topic.
Practical things like software development, can only be learned with constant practice, preferably, while working on a project that is actually meaningful to you and not your grades.
Don't misunderstand me. I'm not saying that you should quit college. I'm just saying that it's not enough. If you don't do some self-learning in addition, you're gonna graduate without any actual skills and with only random information noise in your head.
You’re right. I need to keep practicing after college. Maybe even take some additional courses too
Well I missed quite a lot
ugh I hate the time zone difference
Sorry @keen valve
The difference of time from where I live and the USA is ~9 hours 💀
Anyways, I'm aware I'm probably texting at 4 AM for you, but @keen valve , focus on college and try your best to learn new hobbies. Don't feel bad for asking questions to the community
we're here to help