#Crouching

1 messages · Page 1 of 1 (latest)

livid burrow
#

@vital quarry

vital quarry
#

continue

livid burrow
#

delete the other one

vital quarry
#

which one

#

gotta be specific

livid burrow
#

thread

#

xd

#

anyways for the new function

vital quarry
#

i didnt know you meant thread

#

hehe

#

anyway

#

continue

livid burrow
#

name it Crouching or someth that is related to crouch

vital quarry
#

name WHAT

#

oh

#

the new function

#

right

livid burrow
#

0___0

vital quarry
#

sorry

#

wait

#

ok

#

ok

#

ok

livid burrow
#

fix the reds

vital quarry
#

i did

#

we still dont have a center variable

#

was i supposed to make one?

livid burrow
#

we already have

#

its just that haven't really used it yet

livid burrow
vital quarry
#

hey um dude

livid burrow
#

the program won't recognize the height and center you are using on those two lines of changing controller variables

livid burrow
vital quarry
#

sooo

#

is that ok

#

can we continue

#

will it be gone later?

livid burrow
vital quarry
#

fix it how

#

?

livid burrow
vital quarry
#

you mean the controller? yeah

livid burrow
#

the center variable issue

vital quarry
#

well i dont know how dude

#

treat every word you say like a monkey's paw

#

i have adhd

#

you have to be specific

livid burrow
#

you have to identify the variables and its values before using them

vital quarry
#

how shall i do that

#

its a float

#

so

#

float center;

#

is that good?

livid burrow
#

cut and paste

vital quarry
#

cut and paste where?

livid burrow
#
    void Crouch(float height)
    {
        float center = height / 2;
        (the other two lines of code)
    }
#

welp we're gonna have to take a break first, i shall have things to do at the time being, i shall be back, if you are willing to do this and learm, you can wait or search for other alternatives, its fine for me

vital quarry
#

yeah i did that already

#

mm

livid burrow
#

@vital quarry

#

im back

vital quarry
#

hey

#

so

livid burrow
#

the new function yes

vital quarry
#

the code was interfering with my work on other things

#

sooooooo

livid burrow
vital quarry
#

well actually at first i thought it was that specific code but it was something else

#

i can get the code back real quick

livid burrow
#

so its fine now?

vital quarry
#

or not

#

i guesss i cant just ctrl+z

#

well

#

shit

#

i dont have any of the code for crouching written down

#

but i mean this should be super simple because you already know how to do this right

#

?

livid burrow
#

as long as you know the basics

#

you are fine

#

this is in my movement script as well

vital quarry
#

ok

#

simple enough

livid burrow
#

so on the new function

#

make a new float variable

#

named crouchedheight

#

and then inside that variable

#

make a bool that it checks if the player is crouching

#

mine is like this

vital quarry
#

wait inside the perenthasese

#

?

livid burrow
vital quarry
#

mkay

livid burrow
#
 isCrouching = Input.GetKey(KeyCode.LeftControl);

    void Crouching()
    {
        float crouchedHeight = isCrouching 
    }
#

someth like that

#

make sure its a bool

vital quarry
#

what is the top thing?

livid burrow
#

so that everytime you press left control

#

"iscrouching" will be true

livid burrow
vital quarry
#

hey you do realize i dont have the code we already had written down yknow?

livid burrow
#

yeah you don't

#

thats why we're making it

#

im teaching you how

vital quarry
#

ok

#

ok

#

continue

#

and i put the iscrouching thing at the top?

livid burrow
#

and then at the start function

vital quarry
#

place down the iscrouching thing

livid burrow
#

isCrouching = Input.GetKey(KeyCode.LeftControl);

vital quarry
#

yeah ok

livid burrow
#

put that

#

or on the update func

vital quarry
#

which one man?

livid burrow
#

update

vital quarry
#

ok

#

correct?

#

the iscrouching thing is in the update function and everything is how it is

#

good

#

continue

livid burrow
#

always remember that when you assign values to variables, always put it at the very top

vital quarry
#

ctrl

#

ctrl works

livid burrow
#

so that the program will know which is which

vital quarry
#

mkay

#

so an if statement

livid burrow
#

wait we are doing something very complex

vital quarry
#

Input.GetKeyDown(KeyCode:ctrl);

#

what should i do

livid burrow
#

we are going to use the ?: operator

#

so make two new variables (crouchheight, standingheight)

vital quarry
#

float?

livid burrow
#

then croucheight is half the current height of your controller

livid burrow
vital quarry
#

yes

#

and my crouchheight is?

livid burrow
#

okay so the "?:" operator is helpful, its like an if-else statement but actually better lmao

livid burrow
#

the one we talked about earlier

vital quarry
#

ok

livid burrow
#
    public float standingheight;
    public float crouchHeight;

    public bool isCrouching;

   void Update()
    {
       isCrouching = Input.GetKey(KeyCode.LeftControl);
    }

    void Crouching()
    {
        float crouchedHeight = isCrouching 
    }

    void Crouch(float height)
    {
        float center = height / 2;

        controller.height = Mathf.Lerp(controller.height, height, 1 * Time.deltaTime);
        controller.center = Vector3.Lerp(controller.center, new Vector3(0, center, 0), 1 * Time.deltaTime);
    }

#

this is the progress so far

vital quarry
#

it was supposed to be an integer?

#

oh wait

#

hehe

livid burrow
#

look again

#

i edited it

#

thats our current progress

vital quarry
livid burrow
livid burrow
vital quarry
#

ok

vital quarry
#

mkay

livid burrow
#

okay now i believe we are on the last segment of crouching

vital quarry
#

cool

livid burrow
#

so

#

make an if statement

vital quarry
#

on update i presume?

livid burrow
vital quarry
#

oh

livid burrow
#

inside the if is

#

check if the controller.height is not equal to the crouchedheight

#
    void Crouching()
    {
        float crouchedHeight =  isCrouching ? crouchHeight : standingHeight;

        if (controller.height != crouchedHeight)
        {
        //code
        }
    }


#

should look like that

vital quarry
#

ok

#

now?

livid burrow
#

now

livid burrow
#
    public float standingheight;
    public float crouchHeight;

    public bool isCrouching;

   void Update()
    {
       isCrouching = Input.GetKey(KeyCode.LeftControl);
    }

    void Crouching()
    {
        float crouchedHeight = isCrouching ? crouchHeight : standingHeight;

        if (controller.height != crouchedHeight)
        {
            Crouch(crouchedHeight);
        }
    }

    void Crouch(float height)
    {
        float center = height / 2;

        controller.height = Mathf.Lerp(controller.height, height, 1 * Time.deltaTime);
        controller.center = Vector3.Lerp(controller.center, new Vector3(0, center, 0), 1 * Time.deltaTime);
    }
#

should look like that

vital quarry
#

pretty much but a bit less organized

#

but

#

there are a few errors

#

2

#

there is no reference for standingheight

#

ohwait

#

thats because mine is named diffrent

#

holdon

#

where did the ceiling come from

livid burrow
livid burrow
#

its from my script

vital quarry
#

oh

#

ok

#

also "Adjustcontroller" does not exist in the current context

vital quarry
#

to what?

vital quarry
#

mkay

#

so

#

i did that

#

no errors

#

at the same place that you think i am

#

whats next?

#

klay?

livid burrow
#

wait sorry i did something

livid burrow
vital quarry
#

ok

livid burrow
#

you have now made the character controller crouch

#

see for yourself

vital quarry
#

if i press ctrl i will crouch?

livid burrow
#

left ctrl

vital quarry
#

mhm

#

ok

#

doesnt seem that way

#

could you take a look at something

livid burrow
#

lemme see

vital quarry
#

oop

#

wait

#

there

livid burrow
#

what happens when you play

vital quarry
#

well

#

everything is the same

#

exceot

#

except*

#

no crouch

#

nothing

#

when i ctrl

#

nothin

livid burrow
#

what does the controller do

vital quarry
#

nothing

livid burrow
#

really

#

interesting

vital quarry
#

yes

#

i dont know why

livid burrow
#

oh well lets finish the thing then

vital quarry
#

i dont think i will have crouching in my game very much anyway

livid burrow
#

oh wait

#

i know why

#

you didnt call the crouch function

#

in the update function

#

so nothing really happens

#

call it after controller.Move

#

i see you took the tutorials from Brackeys

#

@vital quarry whats happeninh

vital quarry
#

yes

#

and?

#

its a good vid

#

nice and simple

#

what of it?

#

@livid burrow

livid burrow
vital quarry
#

oop

livid burrow
#

after the "controller.Move(velocity * Time.deltaTime);"

#

put

#

"Crouching();"

vital quarry
#

like under it?

#

where should i put it

#

like right next to it?

livid burrow
#

under

vital quarry
#

uh ok

#

ok

#

but when i let go of ctrl it doesnt go back

#

it just stays down

livid burrow
#

i see

vital quarry
#

weird is that not?

#

i dont wanna be short for eternity

livid burrow
#

xd

#

wait

#

we gotta finish the whole thing to see if the probem still persists

vital quarry
#

mkay

livid burrow
#
    void Crouching()
    {
        float crouchedHeight = isCrouching ? crouchHeight : standingHeight;

        if (controller.height != crouchedHeight)
        {
            Crouch(crouchedHeight);

            //Vector3 camPosition will be acting as your camera's position
            Vector3 camPosition = MainCamera.transform.localPosition;
            //camPosition will be set to the controller's height
            camPosition.y = controllerName.height;

            //We set the camera's position to the camPosition, which is set to the height of the controller
            MainCamera.transform.localPosition = camPosition;
        }
    }

vital quarry
#

doesnt this mean i would need a camera variable

#

no?

#

ok

livid burrow
#

yeah

#

the camera

#

dont you have one

vital quarry
#

no i have a main camera

#

just not a camera variable in the script

livid burrow
#

make one

vital quarry
#

transform or camera?

#

what is the variable called

livid burrow
#

transform

vital quarry
#

why not the camera variable?

#

oh

#

wait i think i know why

#

nevermind

livid burrow
#

lmao

#

only the transform

#

remember we want the position of the camera to follow the controller

vital quarry
#

it works

#

cool

#

although the time between standing and crouching is a tiny bit slow

#

is that changeable?

livid burrow
#

that's when

#

LerpUnclamped comes in

#

so in order to do that

#

make a new variable

vital quarry
#

called?

livid burrow
#

"timeToCrouch"

#

then set it higher than 1

vital quarry
#

what kind of variable?

#

float or???

livid burrow
#

then change all "Lerp" functions into LerpUnclamped

livid burrow
vital quarry
#

kk

livid burrow
#

oh wait no float

livid burrow
#

then you are set

vital quarry
#

error

#

hello?

livid burrow
#

show the line of code

#

of where the error is

vital quarry
#

well

#

i just changed the variable of int

#

to float

#

and it fixed itself

livid burrow
#

good

#

how does it look now

vital quarry
#

well

#

i have a question

#

if i make the number bigger does it go faster

#

or the other way around?

livid burrow
#

faster

vital quarry
#

ok

#

so i have everything i could want in movement

#

no i have another thing i want to implement

livid burrow
#

I suggest moving out the running and jumping out of the update function

#

put them into separate functions

vital quarry
#

why is that?

livid burrow
#

and then call those functions in the update method

#

like what we did with crouching

livid burrow
vital quarry
#

fair

#

also

#

i have another thing that i want to get out of the way

#

technically 2 things

#

but 1 of them is really easy

#

i think

#

im trying to make a a flashlight

#

and im also trying to figure out how to make the world dark

livid burrow
#

flashlight is

vital quarry
#

spotlight

livid burrow
#

just create a spotlight

#

then position it around the camera

#

adjust the range and intensity and stuff

vital quarry
#

yes but also switching between not having a flashlight and having a flashlight in hand

livid burrow
vital quarry
#

yes

#

like a legit flashlight

livid burrow
#

well

vital quarry
#

but kinda smooth

livid burrow
#

reference the flashlight

#

then have a bool isFlasglightOn so whenever the key is pressed, the flashlight is on or something

vital quarry
#

ok

#

or

#

i could just de-activate the spotlight with a click

#

maybe like a toggle

#

but i dont really know how to do that

#

i might figure it out

vital quarry
#

@livid burrow

#

when i crouch it does a weird thing an then the head bobbing stops and then im unable to jump

#

weirdly enough

#

but i am able to crouch

livid burrow
#

wdym

vital quarry
#

well it bounces me up a little bit

#

then im unable to jump

#

and then i can crouch

#

but my head doesnt bob

livid burrow
#

wdym by bouncing you up

vital quarry
#

it literally pushes me upwards a bit and then brings me back to where i was

livid burrow
vital quarry
#

i dont even know what is happening in that situation

livid burrow
#

do you have a video

#

where you can show

vital quarry
#

uh lemme see what i can do

livid burrow
#

its currently midnight here

#

so im gonna have to rest

vital quarry
#

ok