#Mathf.Clamp
1 messages · Page 1 of 1 (latest)
thats fine with me
heres my code:
transform.position = new Vector2(-5f, topPositionY); // This is what I have right now. it just jumps to where it needs to go with no transition.
transform.position += new Vector3(-5f, moveSpeed * Time.deltaTime, 0); // I'm trying to make it so instead of it glitching, it just goes smoothly and stops at the variable which is the y position. Where would I add the variable topPositionY in the equation here?
Looking at the documentation, they did not exactly make a simple example.
yeah its using all these math terms that brain cannot comprehend at 2:45am lmao
so you want the position to never exceed a certain Y position
yeah i bassically have three positions top middle bottom. the player can switch between those values. before it would glitch to each one just cause i had it set up that way. i wanna feel how it would feel to smoothly transition between those values
would it be easier for you if I sent the script?
Not sure I understand
here ill send the script
no, you need to save it and give me the link
ohh its just like pastebin okay
Yes
and i just have my old way commented out while i figure out this new way for clarification
so usually i have those things not commented out and this new line is not there
oh and the float y variable i just forgot to delete but isnt used anymore
yeah i bassically have three positions top middle bottom. the player can switch between those values.
What happens when the player switches?
I'm not 100% certain I understand what you're doing. Will read over the code.
heres a video
sorry im really bad at explaing this stuff
this is what my code currently does
i want my circle to move between those three points smoothly if possible similar to how the red squares come at the player smoothly and dont jump forward
let me know if that makes sense.
sec
anyone know how i would make the code stop at the topPositionY variable? All it is a value that holds where I want to stop. The code be
Do you mean, not be able to go up another notch?
when it is supposed to be at its highest position
yes. if its at the top position, they shouldnt be able to keep going up. if its at the top position, pressing up should do nothing as only down is available now. This works with the previous implementation, I just don't know how to make it stop with the new way that makes it move smoothly.
okay
have it start at 2
if you start in the middle
when you press W
if the integer does not equal 3
then move up
when you press S
if the integer does not equal 1
then move down
does this make it move smoothly?
cause isnt that what im doing. the code is working i just need it to move between levels smoothly
No, that constrains the movement so that you don't move too far up or down
Then you have missed the finer points of our conversation, or not clearly defined what you need
anyone know how i would make the code stop at the topPositionY variable? All it is a value that holds where I want to stop. The code be
Anyway
ohh
im really sorry i just wasnt clear
the code works it stops when it needs to. it just doesnt with it moving smoothly instead of teleporting
That's alright. It's fairly common with new people who stay up late.
If you want the ball to animate towards its new position, instead of teleporting, then you need to move it frame by frame, using Time.deltaTime to divide the length of moment between the frames.
In your case, you'd need a very basic and slightly creative animation "system" in your code
i see what you are saying
so what I have is this:
transform.position += new Vector3(0, moveSpeed * Time.deltaTime, 0);
should I scrap this or can I work with this to make it do what you are saying.
so where you change its position, you should instead change it's newPosition
while also flipping a bool hasNewPosition
then create a new method, which you'll execute in Update()
in this method, you simply say:
if (hasNewPosition)
and then step or Lerp the transform.position towards the newPosition
ohh so thats how ill implment lerp. cause thats what i was reading. and ive used lerp a long time ago but i just couldnt remember how to get it to work in this situation
thank you so much for the help man. sorry for the confusion. i am very tired LMAO
You're welcome, np.
Probably best to get some sleep before you continue further.
haha yes! i started working on this mini project and i was just like ima grind this out lol. its funny how ive been doing c# and unity for a good bit now but having no sleep just messes with my brain. have a good night man!
sleepiness and hunger are the worst
Good night!