#States

1 messages · Page 1 of 1 (latest)

stoic marsh
#

okay reply here

solar canyon
#

okay

stoic marsh
#

so u do have error

solar canyon
#

so those r the erors

stoic marsh
#

script isn't running

solar canyon
#

yea but those have been there for so long

stoic marsh
#

the first one mainly

#

well they shouldnt

#

because they will cause weird behaviros

#

even if script runs

solar canyon
#

so

#

wait

#

but there is an anim attaced

#

attached

stoic marsh
#

they are easy fix

solar canyon
#

but the thing is

stoic marsh
solar canyon
#

the anim goes away

#

when i play

stoic marsh
#

thats why

#

youre setting it at runtime

#

but its not on the same Object

solar canyon
#

oh

stoic marsh
#

so it doesnt find it

#

if ur setting things in inspector u dont need any of the =

#

in Start

#

anim = GetComponent<Animator>();
controller = GetComponent<CharacterController>();

#

get rid of

#

and get rid of Rigidbody

solar canyon
#

both?

stoic marsh
#

yes both

#

they are useless if u assign them in inspector

#

or they get overriden

solar canyon
#

yea i deleted

#

the stuff is still there tho

stoic marsh
#

which stuff

solar canyon
#

in inspector

#

oh wait

stoic marsh
#

thats fine

#

thats what u want

solar canyon
#

wait now

#

im getting true false stuff in

#

console

stoic marsh
#

yes cause now script is running

solar canyon
#

ok

stoic marsh
#

or properly at least

solar canyon
#

but it still doesnt change states

stoic marsh
#

which state are u in

solar canyon
#

wait

#

im changing

#

its working

#

but my animations are showing up

#

wait

#

what

#

when i frist play gae

#

game

#

my animations work

#

but not he sprint

#

not the

#

wait bro

#

whenever i reload

#

it works

stoic marsh
#

the only thing stuck for me is Air to ground

#

but im looking into it

solar canyon
#

whenever i reload

stoic marsh
#

is an easy ass fix tho

solar canyon
#

the stuff works

#

but not the animations

stoic marsh
#

dont woorry about animations rn

#

get the states working first

#

once states work, the animations will fall into place

solar canyon
#

the states r working

#

wait no

#

they arent

stoic marsh
#

updated code same as mine

solar canyon
#

they only worked

stoic marsh
#

so we're on the same page

solar canyon
#

they only work

#

if i press R

#

should I copy and paste ur script?

stoic marsh
#

yes but only thing is not working is crouching

#

kinda

solar canyon
#

yea im able to sprint while crouching

stoic marsh
#

cause its never going into crouch state

solar canyon
#

oh wait

#

yeah its not

stoic marsh
#

because crouching has nothing in it

solar canyon
#

so put Crouch():

#

;

#

wait no

stoic marsh
#

ops

#

it's never waiting for coroutine to finish

solar canyon
#

reload?

stoic marsh
#

nah the crouching

#

I think it's working now

solar canyon
#

wait

#

it only goes to crouch state

#

if i click

#

it doesnt stay in crouch state

stoic marsh
#

yeah its doing a weird toggle

#

h/o

#

You dont want to exit out of crouch unless wat?

solar canyon
#

wait

stoic marsh
#

cause I accidentally if key is not pressed

#

and if not animatoing in coroutine

#

it exists out immediately after

solar canyon
#

the crouch should be if i hold down, and then let go it should get out ot crouch state

solar canyon
#

of control

stoic marsh
#

ok so what I have with key is correct

#

but h//o

stoic marsh
#

u set this to GetKeyDown thats why

solar canyon
#

oh

#

so should it be just getkey?

stoic marsh
#

yeah h/o let me test sum

solar canyon
#

okay

#

im also tryigng something

stoic marsh
#

ok I think it's fix

solar canyon
#

what did u change

#

I was trying getkey and getkeyup

stoic marsh
#

a few things

solar canyon
#

but nothing is changing

solar canyon
#

so i can see

stoic marsh
#

yes let me test

#

gimmie a second

solar canyon
#

okay

#

thanks for helping me for a few hours

#

i cant thank you enough

stoic marsh
#

ya easy stuff np

solar canyon
#

I was completely lost before u started to help

stoic marsh
#

jumping into statemachines from the beginning like this isn't gonna be easy

#

ah it's stil toggling for but state is fixed

#

lemme see if I can maybe just make 2 coroutines, 1 to stand and 1 to crouchdown

#

ok

#

it works

#

lemme send

solar canyon
#

what did u change

stoic marsh
#

a few things

#

you can compare if you want

#

not much from original

#

just removed a few functions

#

crouch was also being called with keyDown in the handlemovemnt

#

without bool

solar canyon
#

wait dude

#

if I press shift while crouching, it just goes back and forth from sprint and crouch

#

do u know why

stoic marsh
#
          if (sprintKey)
                    {
                        Sprint();
                    }```
#

forgot that

#

yup , removed it and it fixes

solar canyon
#

yea

#

now i gotta fix animations

#

its playing sprint animation if i press shift while crouching

stoic marsh
#

did u remove the sprint from crouch ? no reason it would trigger tat

solar canyon
#

ik im stupid i realized i dont have an isrunning bool anymore. I made all my movements in a blend tree thats why

#

so i have to fix that up

stoic marsh
#

oh ok. as long as the logic works

solar canyon
#

yea

stoic marsh
#

the animation should be easy

solar canyon
#

ye

#

i have to fix the blend tree constraint

#

thank you so much

#

for fixing my problem

#

lifesaver

stoic marsh
#

sure thing!

solar canyon
#

wait i hve one question

stoic marsh
#

ya

solar canyon
#

actually nvm

#

ive asked u so many questions

stoic marsh
#

go ahead

solar canyon
#

okay

#

so

#

actually nvm

#

i can fix it

#

its about the animations

stoic marsh
#

lol okie

solar canyon
#

oh wait

#

if im sprinting, then pressing control to crouch, im still sprinting at that speed

#

do u know how to fix

stoic marsh
#

inside of State crouching

#

shouldbe ```cs
case MovementState.crouching:
{
Speed = crouchSpeed;

                if (!crouchKey && !duringCrouchAnimation)
                {
                    if (isCrouching)
                    {
                        HandleCrouch();
                    }
                }
            }
            break;```
#

you could tehcnically make this the same line anyway

#

if (!crouchKey && !duringCrouchAnimation && isCrouching)

solar canyon
#

yea i fixed it

#

thanks

#

oh yeah my animation problem before was that i could go into sprinting animation while crouching lol

#

and for some reason

#

my blend tree isn't displaying

#

the velocity

#

here its supposed to display the velocity

#

when im playing but it doesnt

stoic marsh
#

I dont see it in the code

solar canyon
#

its in a differnet code

#

that controls my blend tree

stoic marsh
solar canyon
stoic marsh
#

it doesn;t even take into account the movement states

solar canyon
#

yea i made this before movement states

#

so

stoic marsh
#

referennce that

#

or just the character controller

#

get the speed from that

solar canyon
#

the script?

stoic marsh
#

should just be velocity = controller.velocity.magnitude

solar canyon
#

where

stoic marsh
#

remove all the rest in update

stoic marsh
solar canyon
#

huh

#

this is for my beldn tree

#

blend tree

stoic marsh
# solar canyon blend tree
    Animator anim;
    float velocity = 0.0f;

    [SerializeField] private CharacterController controller;




    int VelocityHash;


    void Start()
    {
        anim = GetComponent<Animator>();

        VelocityHash = Animator.StringToHash("Velocity");
    }

    void Update()
    {



        velocity = controller.velocity.magnitude;
        anim.SetFloat(VelocityHash, velocity);

    }```
solar canyon
#

wait why ?

stoic marsh
#

why not?

#

you already have the speeds from character moving

#

just move them over

#

just try it first

solar canyon
#

okay

#

now my animations dont play

#

the old one worked

#

mine

stoic marsh
solar canyon
#

it affected my moement animations

stoic marsh
#

it shouldnt

solar canyon
#

wat

#

i just went back to my old script

#

and now its all messed up

#

neermind