#So what you can do is read `keys` into a
1 messages · Page 1 of 1 (latest)
I don't think I understand what you meant here. Here look at what I have tried to do:
startTimer();
slideCurve.MoveKey(0,); //I am accessing the first the first index, and the second argument is a KeyFrame, which idk what it is
speedDuringSliding = slideCurve.Evaluate(time);
rb.velocityX = speedDuringSliding * direction;
}```
If you are wondering what I am trying to do here, I am trying to move the first key towards the current velocity of the player and the player speed will decelerate by using the AnimationCurve.
i don't understand why you need to modify the animation curve here
so depending on where the current velocity is at, if the player slides, then the player will slide starting at that player velocity
that doesn't make any sense
you start sliding at your current velocity
don't you already know that?
that is exactly what I am saying
why is an animation curve needed at all here?
describe the gameplay you're trying to create here
alright, so when the player moves, there will be an acceleration when running, which is accomplished by using an animation curve. Now if the player decides to slide before reaching its max speed, I want the player to slide starting at the current velocity and then it will slowly go down to zero depending on how the curve is structured. This is why I need to modify the the very first point in the graph.
but the curve's only job is to tell you your current acceleration
or does the curve tell you the velocity you can move at?
show me your entire movement script
oh it is really long code. I have only showed you the fundemental stuff
I think it is this one, which is why I wrote these two lines of code:
speedDuringSliding=slideCurve.Evaluate(time);
rb.velocityX = speedDuringSliding * direction;```
Share the entire thing. I can read it.
here is the code, the part of the code that I am referring to is at line 239 in the slide function https://gdl.space/aqivohutas.cs
sounds like you should just have time go down towards zero during a slide
huh, what do you mean?
you add Time.deltaTime to the time field every time you call run()
why not just do the opposite in slide()?
ohhhh that is actually really smart
startTimer is a bad name for that function
it doesn't start a timer at all
time is also a very vague field name
I'd call it accelerationProgress or something like that
that makes sense, I renamed it incrementTime. Does it sound reasonable?
or that
you should also give it an argument to control how quickly you speed up or slow down
public void SpeedUp(float rate = 1) {
accelerationProgress = Mathf.MoveTowards(accelerationProgress, 1, Time.deltaTime * rate);
}
using MoveTowards stops it from going past 1
and then rate lets you control how quickly it changes
SlowDown would move towards 0 instead of 1
ohh I have never seen that Mathf.MoveTowards function
this is actually very useful
wait I just realized a flaw here, it still wouldn't adjust where the current velocity would be. We are just doing the whole thing in reverse when we could have just done it normaly.
I don't know what "normally" means
rewriting your acceleration curve does not sound very normal to me
I also don't know what you mean by "Adjust where the current velocity would be"
as you run, your acceleration progress moves towards 1
if you slide, the progress moves towards 0 instead
at the moment that you start sliding, your velocity will start going down instead of up
i should point out that MoveKey is changing the animation curve. You'd be permanently changing the shape of the curve.
yea but what if you slide in the middle of your acceleration. Lets say your current velocity is 3, and you start accelerating. In the middle of your acceleration, your current velocity would be at 5 and the max will be 7. Now, if you start sliding, you don't start at a velocity of 5, because remember, it all depends on where the key is placed in the graph. So it can make it start at the walking speed of 3, or start at the max speed of 7. This will be very weird because there is a sudden change in velocity which is why I want to set the keyframe at the current velocity.
yes I am aware of that
your current velocity is 3 because your accelerationProgress is around three-sevenths of the way between 0 and 1
you accelerate up to 5
your acceleration progress is now at 5/7
you start sliding. your acceleration progress is still at 5/7, so your speed doesn't change
then you acceleration progress goes backwards, so your velocity goes down
I do not see the problem.
ok I think it would be better if I draw it out for you.
you see how it goes from a velocity of 5 when accelerating to a velocity of 7 when initiating sliding
the speed diffrence will be noticable
which is why I need the program to automatically set the initial point to where the current velocity will be at
so sliding instantly speeds you up to your maximum velocity?
yea if I set the the keyframe at that point
no keyframes
i am asking you how your game is going to work
you're in an XY problem right now
Y is "how do I set a keyframe on an animation curve?"
so, does sliding instantly put you at your maximum possible velocity?
no, it starts at where the current velocity is at
okay, so if you're at 75% of your maximum speed, and you start sliding, you should be sliding at 75% of your maximum speed
and then slow down until you hit 0%
is that correct?
yes exactly
then what I've described will work perfectly.
when you start sliding, the red dot will begin moving to the left
or do you have a separate animation curve you want to use for slowing down?
I am using a seperate animation curve
okay, that's the important bit
I would suggest just making that curve range from 0 to 1
Store your velocity into a variable when you begin a slide
your velocity is now decelerationCurve.Evaluate(time) * slideSpeed
slideSpeed is set when the silde begins
You could do the same thing for the acceleration curve: make it range from 0 to 1, and store the max speed separately
oh thats interesting, why multiply slideSpeed to decelerationCurve.Evaluate(time). It looks like it will just amplify the speed.
we don't have to mess with the curve
the curve is now "normalized" -- it ranges from 0 to 1, no matter how fast you're actually sliding
it tells you what fraction of your original speed you still have
when you multiply that by slideSpeed, you get your current speed
if the curve is at 0.3, you're moving at 30% of your original sliding speed
ohhh ok yea that makes sense
you're separating the configuration (the curve's shape) from the runtime data (the speed you had when you started sliding)
mixing the two gives you a headache
Hey Fen, I know this discusion happened a long time ago, but I am having a little bit of an issue here.
When applying what you have told me to my running function (aka acceleration), it works perfectly
however, when applying it to my sliding function, it is giving me a janki result
here is my code:
SpeedDown(slideRate);
speedDuringSliding = slideCurve.Evaluate(deccelerationProgress) * initialHorizontalSpeed; //Multiply the initial horizontal speed to start sliding at the current velocity
rb.velocityX = speedDuringSliding * direction;
private void SpeedDown(float rate = 1) {
deccelerationProgress = Mathf.MoveTowards(deccelerationProgress, 0, Time.deltaTime * rate);
}
```
I have debugged the deccelerationProgress value and the x velocity, and the result was that as the deccelerationProgress drops down, the x velocity becomes 0 before deccelerationProgress even reaches 0
you shouldn't be changing speedDuringSliding constantly
you should set it once when you start to slide
what do you mean? If the player wants to slide, he has to decelerate, and therefore changing the velocity. Meaning speedDuringSliding will have to change, right?
No. speedDuringSliding is how fast you were going when you started to slide.
Oh, I misunderstood
You have a separate initialHorizontalSpeed
Perhaps you're changing initialHorizontalSpeed somewhere else?
ohh wait maybe it might be that
ill check
yes, you were right. I have this function right here:
private void recordHorizontalMovementSpeed() {
if (Input.GetKey(KeyCode.A) == true) {
initialHorizontalSpeed = -rb.velocity.x;
}
else if (Input.GetKey(KeyCode.D) == true) {
initialHorizontalSpeed = rb.velocity.x;
}
}
how do I not make a variable change after saving it? I know that I have to save it to another temporary variable, but that variable will also change with it.
don't record the current speed if you're not running
oh yea that makes sense
ok now it works as intended 🙂
one last question
how do I make the sliding stop at a velocity of 4. (meaning once the velocity reaches 4, then the velocity will be equal to 0)
is there an easy way I can I can do this in the calculation without using any if statment?