#Crouching
1 messages · Page 1 of 1 (latest)
continue
delete the other one
name it Crouching or someth that is related to crouch
0___0
fix the reds
put the float variable first
the program won't recognize the height and center you are using on those two lines of changing controller variables
exactly
fix it first
have you fixed this?
you mean the controller? yeah
the center variable issue
well i dont know how dude
treat every word you say like a monkey's paw
i have adhd
you have to be specific
put this above everything else
you have to identify the variables and its values before using them
cut and paste
cut and paste where?
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
the new function yes
which are?
well actually at first i thought it was that specific code but it was something else
i can get the code back real quick
so its fine now?
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
?
yep
as long as you know the basics
you are fine
this is in my movement script as well
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
no no
mkay
isCrouching = Input.GetKey(KeyCode.LeftControl);
void Crouching()
{
float crouchedHeight = isCrouching
}
someth like that
make sure its a bool
what is the top thing?
assigning the bool to a key
hey you do realize i dont have the code we already had written down yknow?
public bool isCrouching;
and then at the start function
place down the iscrouching thing
isCrouching = Input.GetKey(KeyCode.LeftControl);
yeah ok
which one man?
update
ok
correct?
the iscrouching thing is in the update function and everything is how it is
good
continue
put the iscrouching thing at the very top
always remember that when you assign values to variables, always put it at the very top
so that the program will know which is which
wait we are doing something very complex
we are going to use the ?: operator
so make two new variables (crouchheight, standingheight)
float?
then croucheight is half the current height of your controller
float because i reckon your height had a decimal
okay so the "?:" operator is helpful, its like an if-else statement but actually better lmao
half of your original height
the one we talked about earlier
ok
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
no
look again
i edited it
thats our current progress
void Crouching()
{
float crouchedHeight = isCrouching ? crouchHeight : standingHeight;
}
just copy what i did
here
ok
then do this
mkay
what this does is that if isCrouching is set to true, the crouchHeight value will be returned, else the standheight will be returned
okay now i believe we are on the last segment of crouching
cool
on update i presume?
on the crouching
oh
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
now
call the function crouch
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
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
its orgranized wym
change it
to what?
here
i fixed it
mkay
so
i did that
no errors
at the same place that you think i am
whats next?
klay?
wait sorry i did something
you are actually done
ok
if i press ctrl i will crouch?
left ctrl
lemme see
oop
wait
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
there
what happens when you play
well
everything is the same
exceot
except*
no crouch
nothing
when i ctrl
nothin
what does the controller do
nothing
oh well lets finish the thing then
i dont think i will have crouching in my game very much anyway
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
do this
oop
under
i see
mkay
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;
}
}
make one
transform
lmao
only the transform
remember we want the position of the camera to follow the controller
it works
cool
although the time between standing and crouching is a tiny bit slow
is that changeable?
yes
that's when
LerpUnclamped comes in
so in order to do that
make a new variable
called?
then change all "Lerp" functions into LerpUnclamped
int
kk
oh wait no float
and then change all the 1s with timeToCrouch
then you are set
well
i have a question
if i make the number bigger does it go faster
or the other way around?
faster
ok
so i have everything i could want in movement
no i have another thing i want to implement
I suggest moving out the running and jumping out of the update function
put them into separate functions
why is that?
it makes the code look nicer and easier to navigate
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
flashlight is
spotlight
just create a spotlight
then position it around the camera
adjust the range and intensity and stuff
yes but also switching between not having a flashlight and having a flashlight in hand
skybox and other lighting settings
turn off and on?
well
but kinda smooth
reference the flashlight
then have a bool isFlasglightOn so whenever the key is pressed, the flashlight is on or something
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
@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
wdym
well it bounces me up a little bit
then im unable to jump
and then i can crouch
but my head doesnt bob
wdym by bouncing you up
it literally pushes me upwards a bit and then brings me back to where i was
for that you are going to set a condition or something when the player is crouching
i dont even know what is happening in that situation
uh lemme see what i can do
welp im gonna be out for a while
its currently midnight here
so im gonna have to rest
ok