This is my script tried enabeling the rigidbody.AddTorgue, but it will then rotate the axis, rather wanna see the texture "roll/rotate" :)
Player is a ball that can jump and move, when moving right i want it to gain momentum.
void Update ()
{
Vector3 horMovement = Input.GetAxis("Horizontal") * transform.right * Time.deltaTime * PlayerSpeed;
if (Input.GetKeyUp("space") && Physics.Raycast(transform.position, -transform.up, MaxJumps))
{
rigidbody.AddRelativeForce(transform.up * PlayerJumpSpeed, ForceMode.Impulse);
}
//rigidbody.AddTorque(Vector3.right * 1 *Time.deltaTime);
//move player
transform.Translate(horMovement);
}
2 Answers
2
If your player is a ball, why not simply let it rotate? You could still make it jump upwards if you add a force (rather than a relative force) upwards like so:
void Update () {
if (Input.GetKeyUp("space") && Physics.Raycast(transform.position, Vector3.down, MaxJumps)) {
rigidbody.AddForce(Vector3.up * PlayerJumpSpeed, ForceMode.Impulse);
}
// move player by letting them roll the ball
rigidbody.AddTorque(Vector3.right * PlayerRollSpeed * Input.GetAxis("Horizontal") * Time.deltaTime);
}
Try giving that a shot. ('PlayerRollSpeed' should probably be something like 100)
Solved it myself :)
Vector3 movement = (Input.GetAxis("Horizontal") * -Vector3.left * movementSpeed) + (Input.GetAxis("Vertical") * Vector3.forward * movementSpeed);
rigidbody.AddForce(movement, ForceMode.Force);
Did the job :)
I'm a bit confused with your question. Surely if you assigned the texture to your ball, and it rolls, the texture should be rotating as well. I don't see how the ball would roll but the texture not.
– Meltdown