#Character controller

1 messages · Page 1 of 1 (latest)

sonic wind
#

@elfin dragon cmere

elfin dragon
#

alright

#

It'll take me a bit

sonic wind
elfin dragon
#

typo

sonic wind
#

we already made the function, now we just want to use it

true heath
#
public int Clamp(int value, int min, int max) {
  if (value > max)
  {
    value = max;
  }
  else if (value < min)
  {
    value = min;
  }
  return value;
}

Code from earlier

elfin dragon
#

Clamp(angle.x, -90, 90);

#

im not sure which way ngl

sonic wind
#

it's value, min, max

elfin dragon
#

yeah

sonic wind
elfin dragon
#
transform.eulerAngles.x = Clamp(angle.x, -90, 90); 
sonic wind
#

well you'd set the angle.x itself, since that's what we're modifying

elfin dragon
#

aha

#

im pretty dumb sometimes

true heath
#

Note, the unity clamp function says:

Returns an undefined value if the minimum value is greater than the maximum value.
So it won't throw an error if you get the min max the wrong way round, it will simply stop working

true heath
true heath
#

But I would assume so

elfin dragon
#

it works

#

thanks

sonic wind
#

there we go!

elfin dragon
#

I'll probably forget some of this ngl

sonic wind
#

though, you might want to mod (make it wrap around) your y angle by 360

elfin dragon
#

wdym

sonic wind
#

just angle.y = angle.y % 360

elfin dragon
#

wait what does that do

true heath
#

Remainder of division

sonic wind
#

it makes it wrap around to 0 when it reaches 360

#

think of it like a remainder, or like the hands of a clock

true heath
#

Wouldn't that give a fraction from 0-1 though?

elfin dragon
#

oh

#

alright

true heath
#

Wait

#

No

#

It's the leftover not the decimal place

#

Mb

elfin dragon
#

now I know why look sensitivity wasn't doing anything

#

i wasnt

#

using it

sonic wind
#

yeah

elfin dragon
#

im genius

#

I forgot how to do it

#

wait

#

forgot how to lofk

#

nvm

sonic wind
#

how to do what?

elfin dragon
#

nevermind I have