- Home /
Rigidbody speed / Velocity issue
hii all ,
I am making game like : https://play.google.com/store/apps/details?id=com.egs.games.nobrakes
I have did code for moving and turning my player :
void FixedUpdate () {
if(Camera.main.orthographicSize == 18)
{
ON = true;
trees.SetActive(true);
}
if(ON)
{
rigidbody.drag = 0.8f;
rigidbody.angularDrag = 0.05f;
score = Convert.ToInt32(velocity);
speedTxt.text = velocity.ToString ();
Movement();
SpeedControl ();
}
}
void Movement()
{
if(!gameOver)
{
rigidbody.AddForce (transform.forward * speed);
//rigidbody.velocity = Vector3.ClampMagnitude (rigidbody.velocity, 100.0f);
velocity = Mathf.Round (rigidbody.velocity.magnitude * 5.0f);
if(Input.touchCount > 0) {
Input.multiTouchEnabled = true;
for(var i = 0; i < Input.touchCount; i++)
{
if(Input.touches[i].phase==TouchPhase.Stationary || Input.touches[i].phase==TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay (Input.touches[i].position);
//Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit ;
// Check what is under the pointer
if (Physics.Raycast (ray, out hit, Mathf.Infinity))
{
if(hit.collider.name == "Left")
{
yRotation -= 4.0f;
transform.eulerAngles = new Vector3(0, yRotation, 0);
//rigidbody.AddForce (-transform.right);
rigidbody.AddForce (transform.forward * speed);
rigidbody.angularDrag += 5.0f;
rigidbody.drag += 1.0f;
}
if(hit.collider.name == "Right")
{
yRotation += 4.0f;
transform.eulerAngles = new Vector3(0, yRotation, 0);
//rigidbody.AddForce (transform.right);
rigidbody.AddForce (transform.forward * speed);
rigidbody.angularDrag += 5.0f;
rigidbody.drag += 1.0f;
}
}
}
}
}
}
}
void SpeedControl()
{
if(Application.loadedLevelName == "1" || Application.loadedLevelName == "2" || Application.loadedLevelName == "3")
{
if(velocity <=105)
{
speed += 0.004f;
}
if(velocity > 105 && velocity <=130)
{
speed += 0.003f;
}
if(velocity > 130 && velocity <=190)
{
speed += 0.002f;
}
if(velocity > 190 )
{
speed += 0.001f;
}
}
}
But while turning , speed is decreasing too much and then its not increasing fast so if my speed is 40 and if i drift then it will become arround 25 and then its not increasing fastly. So player keeps moving in between range of 20 - 50 if he continues to take turn.
Hope you guys help me.
Thanks..
Plz someone help me.. How can i move my object left right so that velocity does not change that much..
Your answer
Follow this Question
Related Questions
Keeping momentum with rigid bodies. 0 Answers
Linear Velocity 1 Answer
instantiated objects have different speed 1 Answer
Comparing rigidbody speeds 1 Answer
How Do I Increase the ForwardForce of the player over time? using rigid body 2 Answers