- Home /
Mathf.Smoothdamp, need help troubleshooting!
Hi,
I have an object rolling at a speed, with a deceleration. When i pick up muffins in the level, the object gains a speed, and I want that speed to be gained over smoothtime with smoothdamp. Here is my code:
if (other.gameObject.tag == ("Muffin") && Time.time - muffinpickuptime >= muffinminicooldown) {
muffinpickuptime = Time.time;
Destroy (other.gameObject);
gainingspeed = true;
moveDirection.x = Mathf.SmoothDamp(moveDirection.x, moveDirection.x + MuffinSpeed,ref moveDirection.x,muffinSmoothTime,maxspeedx);
furthermore I disable all deceleration with a gaininspeed check, so there is no deceleration as long as smoothdamp is running (setting it to false after muffinsmoothtime seconds) So i am 100% sure that there are no other lines of code changing the value of moveDirection.x.
What happens when I pick up a muffin now, is that i only get 0.2 more speed on my object, while my muffinspeed is set to 5. I am 100% sure they collide. simply checking for the gainspeed bool in update and putting the smoothdamp there did not help, and gave weird results.
I tried with having 0 as speed also, with no results.
Anything I have overlooked? Can anyone see my mistake?
PS: using a character controller and moving it every frame with value moveDirection.
Thanks for your time :)
Alright, in the 5 hours I was waiting for mod approval, I found out that if I dont put the smoothdamp in update, it will only run for that one frame that the muffin is hit.
So I went back to checking for the bool, and threw it in the update. It is not exactly precise. I want a gain of 5 in speed, and it adds between 4 and 6.5. The higher speed, the more it adds. Also it doesn't care about my muffinspeeed actually. It just keeps on adding its own speed for as long as it's active, which means the longer smoothtime, the more speed will be added in the end. I found my sweet spot though.
I also realised that if i say movedirection.x+muffinspeed as target, the target will be ever changing, therefore I stored the speed as it hit the muffin, and used that speed + muffinspeed. I still have the same result though. It is not game breaking, cos I achieved the effect that I wanted. The little deviation in the speedgain is just a tad annoying and I would of course love to have it fixed.
Your answer
Follow this Question
Related Questions
Ramping animation speed 2 Answers
How can I smooth out the crouch movement? 1 Answer
Whole number Mathf.SmoothDamp ? 1 Answer
How does Mathf.SmoothDamp's max speed work? 1 Answer
SmoothDamp: reference velocity always 0 0 Answers