- Home /
Constant Force and Velocity
Hi! So I have a constant force that is pushing my player upwards for my game but I also have a script that whenever you move left or right it sets the velocity to something pretty low so you don't infinitely move to the left or right. But whenever I move left or right it sets the velocity lower which also completely stops my constant force so it take like 5 seconds to reach max speed again which really messes things up for me. I know this may sound confusing but I'd really enjoy some help.
How are you setting the velocity when you move left/right? if you are assigning a new vector, remember to set the new vector's Y component to whatever the current Y velocity is, so you preserve the Y velocity.
Answer by madks13 · Jul 25, 2018 at 08:29 AM
As mentionned by bobisgod, you need to keep the current vertical velocity, and set only the horizontal velocity. Assuming your vertical velocity is on y axis, and horizontal on the x axis :
Vector3 velocity = new Vector3(horSpeed *Input.GetAxis("horizontal"), transform.velocity.y, transform.velocity.z)
this should slove your problem.
Your answer
Follow this Question
Related Questions
I WILL GIVE YOU 3 DOLLARS to answer this constantforce question 4 Answers
Horizontal Drag, no Vertical Drag 1 Answer
Constant force motion: s = s0 + v0 * t + a0 * t * t. Why? 1 Answer
Velocity powered rigidbody on a moving platform without parenting. 3 Answers
Can an instantiated object inherit its parent's velocity? 2 Answers