- Home /
Move Ball With Same Velocity on Slope
I want to move ball with on incoming slopes as like it was moving in plain ground. At present when slope started ball velocity get reduced so overall ball movement get reduced as per game player experience.
I want to keep same velocity when its moving on ground or sloppy areas.
Though following image I tried to explain my problem:
Here is the code snippet that I was using:
void FixedUpdate ()
{
if (!GameManager.Instance.IsGameRunninng) {
myRigidBody.velocity = Vector3.zero;
return;
}
if (isJumper) {
isJumper = false;
myRigidBody.AddForce (Vector3.up * 35f, ForceMode.Impulse);
}
isGrounded = Physics.Raycast (rayTransform.position, Vector3.down, 0.5f, groundMask);
Vector3 nextVelocity = myRigidBody.velocity;
nextVelocity.x = ballInputHandler.horizontalInput * smoothnessX;
if (!isGrounded) {
nextVelocity.y -= speed * 0.3f;
} else {
nextVelocity.y = 0;
nextVelocity.z = speed;
}
myRigidBody.velocity = Vector3.Lerp (myRigidBody.velocity, nextVelocity, smoothnessValue * Time.fixedDeltaTime);
ClampingBallMovement ();
}
I hope you got my problem correctly, give me some suggestion so I can come over from this problem.
I would just get the surface normal and check if there's an angle and set velocity accordingly.
@myzzie can you able to give me in detail reply? if become possible then with some code too...
https://docs.unity3d.com/ScriptReference/RaycastHit-normal.html
Not sure what else you need?
Answer by tormentoarmagedoom · Aug 29, 2018 at 10:28 AM
Good day.
I never use rigidbodies and velocity, but i supose the best solution is to get the velocity vector when is in the slope, and modify this vector to be magnitude 5. So normalize the vector (magnitude1) and multiply by 5.
VelocityIwant = 5* ActualVelocity.normalized
Bye!
what is we are already getting normalised vector in lower value rather than near to 1 - if you check my code then in z I was constantly applying target speed value.
Your answer
Follow this Question
Related Questions
Throwing knife doesn't throw correctly 0 Answers
Throwing a Spear 1 Answer
Countering AddForce by Modifying velocity 3 Answers
Apply Gravity to Car Physics 0 Answers
Fps Movement Velocity Decrease 0 Answers