#Help

1 messages · Page 1 of 1 (latest)

restive steppe
#

can u help me here please

sterile heron
#

this is the answer:

gusty crag
#

Yes?

restive steppe
#

ok thank you

#

so my problem is the animations

#

i have buttons its for mobile

gusty crag
gloomy ibex
#

all that ifs can be flattened

restive steppe
gusty crag
#

Im weak in the animation and ui stuff

restive steppe
#

ok

sterile heron
restive steppe
#

ok so there is na error messgae and i dont know how to fix it

sterile heron
restive steppe
#

but it all is

sterile heron
#

is the script on another object maybe?

#

where it isnt assigned

restive steppe
#

can u dumb it down?

gloomy ibex
#

You are using start not Start

sterile heron
#

that wouldnt show as an error or anything anyway

restive steppe
#

thank you

#

wait 1 more thing aswel

gloomy ibex
#

still configure your IDE

restive steppe
#

how do i flip the charactor depending on the way it is going

#

so if its going left i want ti to face left

sterile heron
#

then use .flipX = true

restive steppe
#

oh ok

restive steppe
restive steppe
#

@sterile heron caan u help me again please

sterile heron
#

if your gonna ping at least give a question

#

dont just give random useless pings

restive steppe
#

ok sorry

#

it says unnasigned use of local veriable

#

but its used

sterile heron
#

because state isnt set to anything, its just created

#

by default you can set it to idle or whatever you want

restive steppe
#

how

#

i have this anim.SetInteger("state", (int)state);

sterile heron
#

the same way you set it elsewhere

#

line 43 and 49

restive steppe
#

like this

sterile heron
#

yes

restive steppe
#

ok i test

#

even when im moveing it just is idle

sterile heron
#

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

restive steppe
#

whats the class scope

sterile heron
#
public class ...
{
    //here
}
restive steppe
#

puut what into a class

#

change the void to a clas

sterile heron
#

what

#

i said move the variable to the class scope

#

i showed you what the class scope is

#

so just move it there

restive steppe
#

what do i put as the three dots

sterile heron
#

you literally already have that

#

you dont add or remove or change anything

#

apart from that 1 line for the movement state

restive steppe
#

still dont get it

sterile heron
#
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
    }
}
restive steppe
sterile heron
#

line 33 is still there

#

in the exact same spot

#

not moved

restive steppe
#

ok moved it

#

nope still is just idle

sterile heron
#

where did you move it

restive steppe
#

wait ill brb in 5

#

ok im back

#

what should i do @sterile heron

sterile heron
#

of where you set it to running and idle

restive steppe
#

?

#

its all correct

sterile heron
#

how do you know

restive steppe
#

ive checked

sterile heron
#

show the full code

restive steppe
#

theres the error

sterile heron
#

like i said earlier, you need to set it to idle in Start

restive steppe
#

this is what my code looks like now

sterile heron
#

cant see anything

restive steppe
#

what one do you sue

sterile heron
#

what?

restive steppe
#

'''cs

sterile heron
#

use a paste site

#

not the code block

restive steppe
sterile heron
#

what is that

restive steppe
#

the paste

sterile heron
#

all you had to do was paste the code and copy the link

restive steppe
sterile heron
#

and the problem is the animation stays at idle? the state? or what

restive steppe
#

stays at idle

sterile heron
#

the animation, the state, or both

restive steppe
#

how do i check

sterile heron
#

by logging the value with debug.log

restive steppe
#

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

sterile heron
#

how about make the left arrow make direction -1, the right arrow direction 1

restive steppe
#

they are all set uip so right is 1 and left is 2

#

but the run anim dfoesnt work

sterile heron
#

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

restive steppe
#

can you explain the coode

sterile heron
#

and this can never be 0, unless you call it from Update or something manually by giving it 0

sterile heron
#

except its multiplying the speed by the direction

#

which automatically handles going left or right

restive steppe
#

s ohow will it know if i press left or right

sterile heron
#

yes

#

because you give it -1 for left, 1 for right

#

and the rest is just simple math

#

literally 1x1

restive steppe
#

ohh

#

okc

#

ok done taht

sterile heron
#

ok so testing the code, it should be running when you move left or right

#

and move in the correct direction

restive steppe
#

i tested it it moves in the right idr but not running

sterile heron
#

are you calling this method from anything else? or only the buttons

restive steppe
#

i think its the animations thats not working

#

i set it to 1 manually but it wont ru

sterile heron
#

oh right

#

the animation isnt even being played

restive steppe
#

yea

#

the jump anmd fall work

sterile heron
#

add the anim.SetInteger("state", (int)state); line

restive steppe
#

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

restive steppe
#

@sterile heron bro please

sterile heron
#

maybe using Update to handle all the logic and states and stuff

#

instead of doing it all when you press a button

restive steppe
#

i cant

sterile heron
#

all the button should handle is int direction and give it either -1 or 1 or 0

restive steppe
#

ill just use a charator with a cloak and not need to do the animations

sterile heron
#

if you have like 2 hours without being tired, then you can easily fix all of this

restive steppe
#

I've spent 4 on it

sterile heron
#

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