Search Unity

Need help with Torque and Angular Velocity.

Discussion in 'Scripting' started by conorpo2, Aug 29, 2015.

  1. conorpo2

    conorpo2

    Joined:
    Aug 29, 2015
    Posts:
    1
    So I have been working on a 3D platformer with a fixed camera angle. I have already setup the camera, the player and the first scene. I made some basic movement code for my player in C#. Here it is:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Movement : MonoBehaviour {
    5.     public float rotationspeed = 100.0f;
    6.     public float maxrot;
    7.  
    8.     // Update is called once per frame
    9.     void Update () {
    10.         Rigidbody rb = GetComponent<Rigidbody> ();
    11.         rb.maxAngularVelocity = maxrot;
    12.         var rotation = Input.GetAxis ("Horizontal") * rotationspeed;
    13.         rb.AddRelativeTorque(Vector3.back * rotation);
    14.     }
    15. }
    Now this code is good and all, but I have 1 slight problem with it. The ball/player takes forever to change direction. If I'm going full speed one way, and then I change direction. He slows down for about 3 seconds, turns, then speeds up for about 3 seconds. Any idea on how to speed this up. Also if you could help with an accelartion code, that would be very helpful. I want the player/ball to slight increase in speed as time goes on.
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    You could put a PhysicsMaterial on it with bigger friction, however this may slow down acceleration.