#Help
1 messages · Page 1 of 1 (latest)
this is the answer:
Yes?
Im out
all that ifs can be flattened
Im weak in the animation and ui stuff
ok
then dont contribute, your wasting channel space
Bruh
ok so there is na error messgae and i dont know how to fix it
something is null and not assigned
but it all is
can u dumb it down?
that wouldnt show as an error or anything anyway
u fixed it
thank you
wait 1 more thing aswel
still configure your IDE
how do i flip the charactor depending on the way it is going
so if its going left i want ti to face left
referenc the SpriteRenderer
then use .flipX = true
oh ok
fixed
@sterile heron caan u help me again please
what the fuck do you want me to help you with
if your gonna ping at least give a question
dont just give random useless pings
because state isnt set to anything, its just created
by default you can set it to idle or whatever you want
yes
oh, probably because its constantly setting it to idle
maybe you should make the variable be in the class scope instead, and set it to idle in Start
whats the class scope
public class ...
{
//here
}
what
i said move the variable to the class scope
i showed you what the class scope is
so just move it there
what do i put as the three dots
you literally already have that
you dont add or remove or change anything
apart from that 1 line for the movement state
still dont get it
public class ...
{
//Class scope
// - move it to here
public void Something()
{
//Local to Something cant be used anywhere else
float myFloat; //- move this from here
}
}
?
where did you move it
well probably the logic is broken
of where you set it to running and idle
how do you know
ive checked
show the full code
like i said earlier, you need to set it to idle in Start
what one do you sue
what?
'''cs
what is that
the paste
all you had to do was paste the code and copy the link
and the problem is the animation stays at idle? the state? or what
stays at idle
the animation, the state, or both
how do i check
by logging the value with debug.log
if i change the int manually it works
wait
when i put it aas 1 the run doesnt work
but all the arrows to run is 1
how about make the left arrow make direction -1, the right arrow direction 1
and then in the code you can do
public void Movement(int dir)
{
//left = -1; right = 1;
if(dir != 0)
{
rb.velocity = new Vector2(Speed * dir, 0);
state = MovementState.running;
if(dir == -1) spriteRenderer.flipX = true;
else spriteRenderer.flipX = false;
}
}
and thats all the running done in 4 lines instead of all the lines you have
can you explain the coode
and this can never be 0, unless you call it from Update or something manually by giving it 0
its basically the same as what you had
except its multiplying the speed by the direction
which automatically handles going left or right
s ohow will it know if i press left or right
yes
because you give it -1 for left, 1 for right
and the rest is just simple math
literally 1x1
ok so testing the code, it should be running when you move left or right
and move in the correct direction
i tested it it moves in the right idr but not running
are you calling this method from anything else? or only the buttons
i think its the animations thats not working
i set it to 1 manually but it wont ru
add the anim.SetInteger("state", (int)state); line
0 = idle 1 = run 2 =jump 3= fall
when its 1 it should rub
run
it works for 2 where it jumps
and 0 should be idle
@sterile heron
ok so it can change from idle to run now but not run to anything
i think its the code
@sterile heron bro please
idk how to help, apart from re writing the entire code and animator
maybe using Update to handle all the logic and states and stuff
instead of doing it all when you press a button
i cant
all the button should handle is int direction and give it either -1 or 1 or 0
ill just use a charator with a cloak and not need to do the animations
if you have like 2 hours without being tired, then you can easily fix all of this
I've spent 4 on it
well 4 isnt much, unless you have a time limit or something
last time i tried i had to rewrite the entire state machine like 5 times just so that it could work properly
spending alot of time is common in development and coding, thats the main process
the main thing you would want is
void Update()
{
if(//SomeLogic)
state = MyState.idle;
}
``` and same for all states, once you have states figured out then you do
```cs
switch (state)
{
case MyState.idle:
//play animation
//do stuff that are idle related
break;
case MyState.running:
//running stuff
break;
}
``` and it should look something like this fully complete