is there any way to increase the speed while a bool is true by a set amount and include the other forces acting on that object? For example, if the object is traveling at 20 and you set the bool to true, than for all frames until the bool becomes false the object travels at speed 30 (assuming that whatever is making the object travel at 20 doesn’t change) . Just setting the velocity to velocity + speed does not work because it accelerates out of control. Basically what I’m asking about is a method of increasing velocity by a set amount, without overriding the forces pushing on said object. I would be so grateful if you could get this to work.
Boost Car's Speed by Certain KpH value this is almost the same thing, you can use ForceMode.VelocityChange to apply just enough force to get the velocity change that you want.
Thanks a ton for your response, but this solution seems to have the same accelerating out of control problem that Velocity = velocity + speed. has. Could you show me how to implement this in code?
Well instead of activating it with a bool how about using an int for the number of physics steps you want to accelerate over and just adding a fraction of the total velocity each step, each step decrement the int. Only allow user input to reset the int once it has reached zero. Have a go and post back any problems.
\
Thanks so much again for your response, but this has sort of a quick ecceleration and then deceleration. I intend to use this for player movement so I would like the speed to be as constant as possible.
\
Thanks so much again for your response, but this has sort of a quick acceleration and then deceleration. I intend to use this for player movement so I would like the speed to be as constant as possible.
Post some code for a simple replicator, explain exactly what you want it to do and explain what it actually does that you are unhappy with.
I think the fundamental issue you’re having here is “velocity = velocity + speed”
If speed is your extra 10 you want to add, then yes it’s going to keep adding 10.
You want:
addVelocity = speed - velocity, where speed is 30, then
Velocity = velocity + addVelocity
So perhaps:
Speed = transform.forward * 30
Velocity = velocity + (velocity-speed)
You’re just adding the extra speed you need between what you got and what you want. But of course now, if you’re going faster than 30, this will slow you down to 30, which you might not want if going downhill or something, then you’ll need to add extra conditions etc.
I’m having a similar issue to yours in my post in finding the best method to use to add that velocity, just wanted to point out that you need to calculate what you want - what you got and apply the delta. Likely, addForce(addVelocity, ForceMode.VelocityChange).
Thank you alot, that’s very helpfull, and sorry if my question was a little confusing