#Help Wanted - Convert If Input.GetAxis...
1 messages · Page 1 of 1 (latest)
WASD is working correctly
as well as with the sticks
but the issue is the jump/attack/infect
which won't work on the controller
Jump works, but will let u infinitely jump
so your question is about buttons, not input.GetAxis
@loud cloak my code was:
controls.Player.Jump.performed += ctx => JumpKey();
can you show your jump button configuration
But as per the thread it said to do
controls.Player.Jump.performed += JumpKey();
So I did the latter
and then did
void JumpKey(InputAction.CallbackContext ctx) { player.AddForce(new Vector2(0, hostJump), ForceMode2D.Impulse); }
but that glitches out
and doesn't work correctly
show me plz
okay. so do you know if your callback is being called multiple times while you're holding down the button? or just once
well currently it breaks with the
Edit: I tried doing this in my code and it did not work.. it says stuff about CallbackContext not existing, then if I change it to InputMaster.CallbackContext ctx, then it would
Assets\Scripts\Player.cs(39,43): error CS7036: There is no argument given that corresponds to the required formal parameter 'ctx' of 'Player.JumpKey(InputAction.CallbackContext)'
Assets\Scripts\Player.cs(39,9): error CS0029: Cannot implicitly convert type 'void' to 'System.Action<UnityEngine.InputSystem.InputAction.CallbackContext>'
from what i wrote in the thread after trying to implement a forumers advice
you said it was repeatedly jumping
now it breaks?
anyway let me ask you this
which control scheme does this button interaction belong to
Jump? I'm confused sorry
if i hold down A for example (button south) it only jumps once
but if i spam A, I can unlimited jump
oh
right
and it had code for "!jumping"
but that doesnt work with the new input system
for some reason
why not
show me
what code you used to try to make it work
ah i sent it to u
hey sorrry
just went bathroom
Jumping is set true at the end of that if statement
its against server rules to send unsolicited dm's btw
again the expected way to send code is via paste links
so i'm not sure how it gets set back to false, but apparently it's happening more frequently than you expect
show me your whole script. in a paste link
I set it back to the
controls.Player.Jump.performed += ctx => JumpKey();
but I think the += ctx makes the jumpkey
work anytime u press it
without the condition
show me the whole script. in a paste link
okay good so first
it can't be a problem with Start because start only gets called once, and your problem is clearly that jumping keeps being reset to fals
this is the only place besides start where jumping = false is set
your callback for this event is literally the JumpKey() method, so you are guaranteed that the internals of that method are going to run when you press that button
so it's not skipping anything
yeah so it's saying jumping = false when u are touching the ground
as the ground is tagged ground
since we know Jumpkey() is called when you press the button, and jumping=true is set as long as host != null and jumping == false, we should reasonably assume it's being set to true, and it's being set back to false elsewhere
SINCE i just mentioned that there's only one place in the code that's setting jumping = false multiple times, where do you think the problem is occurring?
that's where i'd look
what i would do inside the comparetag on 181 is "Debug.Log("hit ground")
and just see what happens in the console as you're playign
kk
okay
it doesnt do hit ground when in air
and u can infinetely jump[
even commenting out that code
u can still infinintely jump
which means it cant be that line (since if it was commented out, u should never be able to jump again after ur first jump as jumping is never set back to false)
oh
so read this statement to me in human language
have you done logic tables before?
if the player is not in a host (you can take over enemies) and jumping == false (u are not in the air)
Then add force to the player to make them go up on the y axis
Uhh, I'm not sure
oh yeah
in coding classes yeah
in java
if u mean like truth tables
if (host != null && jumping == false)
{
// do one thing
}
else
{
// do something else
}
i mean like discrete mathematics. how to write out a logical inverse
sure
if (x == 10)
the inverse of that would be if !(x == 10)
which would be if (x != 10)
or
if (x == 10 && x < 100)
inverse would be !(x == 10 && x < 100)
which would be (x != 10 || x >= 100)
mm okay yeah i did do discrete maths, failed it the first time then credited it the second time but wouldn't say I was amazing at it lol
you wrote
if (host != null && jumping == false)
the "else" runs when the inverse of that statement is true. can you write out the inverse of that statement
if (host == null && jumping != false)
nope
hmm
it would be
if (host == null || jumping == true)
yes
also
!= false is equivalent to writing == true
and boolean values don't need to be compared against true or false because you're performing a tautology
you can just write
if (host != null && !jumping)
honestly that's what it was but it wasnt working so i changed it... :C
ill try it again tho
BUT WAIT
oh sorry
listen to what i was walking you through
Sorry
your conditions are saying this
if (the host isn't null AND i'm not jumping)
add upward force to the player
Yes
ELSE (meaning if the host IS null OR i AM jumping
add upward force to the player
under all logical branches you're adding upward force
so it doesn't matter if jumping == true or == false
i did notice that but I did not write the code (my project partner did) so I didn't exactly question it, but now trying to get it to work with a controller it glitched out.
Weirdly that was the code when it was on the old input system and it wasn't doing that... unless something chaanged in the meantime weirdly. I'd have to look but yeah what ur saying is right.
now i can't jump at all
if i comment out the second player.addforce
ohh
i think i get it
It's a condition whether ur controlling a host vs if ur in ur own body
e.g. I think what it's meant to write be like
if (ur controlling an enemy)
{ Jump normally
}
else (if ur playing as the normal player)
{
play jump animation
Jump
}
okay. yeah looks like it's just jumbled
i don't blame you the formatting is all over the place. it's hard to tell what scope is where
anywho i think you're on the right path. i am gonna go watch a movie and go to bed. gl!
yes
Which means if the if or else statement run
jumping should be set to true whichever one it runs
then why can i jump instantly again?
correct
i just literally walked you through why
every execution path has an addforce
so it doesn't matter if jumping is true false red blue or elephant
if (jumping) return; // just don't bother executing the rest of the method
if (host)
{
// jump the host
}
else
{
// jump the player
}
if we're already jumping we want to ignore the input
so just short circuit the method if we're jumping
np. glhf!
Now i just gotta figure out
why infect and attack don't work on controller weirdly
they work like half the time :C
and infect crashess the game
but ur going to bed so i asusme i shouldn't bother u
when in doubt, Debug.Log
its fine, just post back in #💻┃code-beginner directly and ask specifically about those