- Home /
moving with rigidbody without acceleration
Hello, I was wondering if it is possible to move with rigidbody without acceleration. So the player has 1 consistent speed throughout, that is top speed instantly when it moves. I've looked into rigidbody.velocity but I am having issue with it since it holds a consistent speed but when jumping it floats around slowly. Also when moving onto a jumping platform that uses AddForce, the player does not register the jump when moving - it sort of does little hops when moving. If i were to stand completely still, the jump registers normally.
Thank you
Without knowing more about your game and seeing your code it is difficult to figure out the right solution. $$anonymous$$aybe you should just be setting the speed of the XZ movement and leaving the 'Y' movement alone.
Here is my movement code to move left:
else if (this.leftController.guiTexture.HitTest(Input.GetTouch(i).position))
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
if (collisioncheck == true)
{
playerFinder.rigidbody.velocity = Vector3.left * 10;
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.left);
playerFinder.rigidbody.velocity = Vector3.Clamp$$anonymous$$agnitude(playerFinder.rigidbody.velocity, 10f);
}
A bit more information. Assu$$anonymous$$g you are only moving left and right, try this:
if (collisioncheck == true)
{
playerFinder.rigidbody.velocity.x = -10.0;
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.left);
}
Note you would assign 10 for right movement.
Thank you for taking the time to answer. playerFinder.rigidbody.velocity.x = 10.0; does not work- I'm getting error CS1612: Cannot modify a value type return value of `UnityEngine.Rigidbody.velocity'. Consider storing the value in a temporary variable
if (Input.touches.Length > 0)
{
for (int i = 0; i < Input.touchCount; i++)
{
//setting right touch movement
var touch = Input.GetTouch(i);
if (this.rightController.guiTexture.HitTest(Input.GetTouch(i).position))
{
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
if (collisioncheck == true)
{
playerFinder.rigidbody.velocity = Vector3.right * 10;
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.right);
playerFinder.rigidbody.velocity = Vector3.Clamp$$anonymous$$agnitude(playerFinder.rigidbody.velocity, 10f);
}
else if (collisioncheck == false)
{
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.right);
playerFinder.rigidbody.AddForce(Vector3.right*4, Force$$anonymous$$ode.Acceleration);
}
/*
else if (touch.phase == TouchPhase.Ended)
{
playerFinder.rigidbody.AddRelativeForce(Vector3.left*0, Force$$anonymous$$ode.Acceleration);
}
*/
}
else if (touch.phase == TouchPhase.Ended)
{
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.back);
}
}
else if (this.leftController.guiTexture.HitTest(Input.GetTouch(i).position))
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
{
if (collisioncheck == true)
{
playerFinder.rigidbody.velocity = Vector3.left * 10;
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.left);
playerFinder.rigidbody.velocity = Vector3.Clamp$$anonymous$$agnitude(playerFinder.rigidbody.velocity, 10f);
}
else if (collisioncheck == false)
{
playerFinder.rigidbody.AddForce(Vector3.left*4, Force$$anonymous$$ode.Acceleration);
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.left);
}
Ahhhh C#. I couldn't tell from your script fragment and guessed wrong. Here is the code fragment in C#:
if (collisioncheck == true)
{
Vector3 v = playerFinder.rigidbody.velocity;
v.x = -10.0f;
playerFinder.rigidbody.velocity = v;
playerFinder.rigidbody.rotation = Quaternion.LookRotation(Vector3.left);
}
Your answer
Follow this Question
Related Questions
Prevent Rigidbody From Rotating 3 Answers
Rigidbody Jumping for Character Controller 1 Answer
Why can't i addforce to a rigidbody? 2 Answers
AddForce Jump Doesn't Work 1 Answer
Roll-A-Ball tutorial error when attaching movement script to ball 0 Answers