#Help Wanted - Convert If Input.GetAxis...

1 messages · Page 1 of 1 (latest)

crimson whale
#

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

loud cloak
#

so your question is about buttons, not input.GetAxis

crimson whale
#

@loud cloak my code was:

controls.Player.Jump.performed += ctx => JumpKey();

loud cloak
#

can you show your jump button configuration

crimson whale
#

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

loud cloak
#

show me plz

crimson whale
#

this?

loud cloak
#

okay. so do you know if your callback is being called multiple times while you're holding down the button? or just once

crimson whale
#

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

loud cloak
#

you said it was repeatedly jumping

#

now it breaks?

#

anyway let me ask you this

#

which control scheme does this button interaction belong to

crimson whale
#

Jump? I'm confused sorry

#

if i hold down A for example (button south) it only jumps once

loud cloak
crimson whale
#

but if i spam A, I can unlimited jump

loud cloak
#

oh

crimson whale
#

when prior, with old input system

#

we had a bool for jumping

loud cloak
#

right

crimson whale
#

and it had code for "!jumping"

#

but that doesnt work with the new input system

#

for some reason

loud cloak
#

why not

crimson whale
#

(basically if ur jumping, u cant jump)

#

I don't know.

loud cloak
#

show me

crimson whale
#

huh

#

where did my code go

loud cloak
#

what code you used to try to make it work

crimson whale
#

it keeps deleting it

#

is that just me?

loud cloak
#

is what just you

#

i don't see any code no

crimson whale
#

it won't let me paste my code

#

it keeps deleting it

loud cloak
#

use a paste link

#

that's the intended way to post code anyway

crimson whale
#

ah i sent it to u

loud cloak
#

when do you set jumping to true

#

hello?

crimson whale
#

hey sorrry

#

just went bathroom

#

Jumping is set true at the end of that if statement

loud cloak
#

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

crimson whale
#

Yeah

#

I think its something to do with the awake code

loud cloak
#

show me your whole script. in a paste link

crimson whale
#

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

loud cloak
#

show me the whole script. in a paste link

loud cloak
#

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

crimson whale
#

yeah so it's saying jumping = false when u are touching the ground

#

as the ground is tagged ground

loud cloak
#

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?

crimson whale
#

hmm

#

so it seems like its bugged thinking its always on the ground?

loud cloak
#

that's where i'd look

crimson whale
#

alright lets see if i comment that out

#

if it still does it

loud cloak
#

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

crimson whale
#

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)

loud cloak
#

oh

#

so read this statement to me in human language

#

have you done logic tables before?

crimson whale
#

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

loud cloak
#
if (host != null && jumping == false)
{
  // do one thing
}
else
{
  // do something else
}
#

i mean like discrete mathematics. how to write out a logical inverse

crimson whale
#

uhh

#

can u show me an example?

loud cloak
#

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)

crimson whale
#

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

loud cloak
#

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

crimson whale
#

if (host == null && jumping != false)

loud cloak
#

nope

crimson whale
#

hmm

loud cloak
#

it would be

if (host == null || jumping == true)
crimson whale
#

if (host == null || jumping != false)?

#

ah damn

loud cloak
#

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)
crimson whale
#

honestly that's what it was but it wasnt working so i changed it... :C

#

ill try it again tho

loud cloak
#

BUT WAIT

crimson whale
#

oh sorry

loud cloak
#

listen to what i was walking you through

crimson whale
#

Sorry

loud cloak
#

your conditions are saying this

#

if (the host isn't null AND i'm not jumping)

#

add upward force to the player

crimson whale
#

Yes

loud cloak
#

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

crimson whale
#

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.

loud cloak
#

your project partner fucked up

#

if it was working before then it wasn't as it is now

crimson whale
#

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
}

loud cloak
#

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!

crimson whale
#

but like

#

the end says

#

Oh

#

But the end says > jumping = true;

loud cloak
#

yes

crimson whale
#

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?

loud cloak
#

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

crimson whale
#

so it should be

#

an else if (!jumping)?

#

ah yes

#

that works

#

finally

loud cloak
#
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

crimson whale
#

right

#

thankyou stroph!

#

Enjoy ur movie 😄

loud cloak
#

np. glhf!

crimson whale
#

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

loud cloak
#

when in doubt, Debug.Log

crimson whale
#

yeah just RB doesn't infect.. unless i die sometimes it works argh

#

yeah all good