Hi, me and another person have been making a breakout clone. We used unity rigidbody real physics to do the ball movement, but the ball always ends up going way to fast over time. We are very new to programming and would like to just finish the game already. Could someone help us by showing us how you would limit the speed of a ridgidbody. Currently when the ball hits the paddle oncollision we have a addforce(x,y,z) also same thing when it hits a wall or brick. but yeah after about 30 seconds its going way to fast to play. We want to limit the speed at a certain speed. Thanks hope someone can help.
using UnityEngine;
using System.Collections;
public class Ball_Movement : MonoBehaviour {
public float count = 0;
public static bool FireBall=false;
public int timeOfBonus = 10;
public static Ball_Movement instance;
public static bool playerDead = false;
void Awake()
{
instance=this;
transform.parent = null;
}
// Update is called once per frame
// When space is pressed the ball launches and breaks free from the parent.
void FixedUpdate() {
if (Input.GetKey ("space"))
{
count++;
AddForce();
}
// bounces from the wall
if (gameObject.rigidbody.collider.CompareTag("wall"))
{
rigidbody.AddForce(-1500, 0, -1500);
}
}
// it is adding score to score not to global Score just change it according to your pref but be carefull xD
void OnCollisionEnter(Collision block)
{
if (block.collider.CompareTag("block10point"))
{
ScoreBoard.Score = ScoreBoard.Score + 10f;
}
if (block.collider.CompareTag("block20point"))
{
ScoreBoard.Score =ScoreBoard.Score + 20f;
}
if (block.collider.CompareTag("loosingwall"))
{
BallCounter.ballCount = BallCounter.ballCount - 1f;
Destroy(gameObject);
if (BallCounter.ballCount <= 0)
{
BallCounter.ballCount = 1;
ScoreBoard.Lives = ScoreBoard.Lives - 1;
playerDead = true;
Destroy(PaddleMove.Instance.gameObject);
}
}
}
void AddForce()
{
if (count < 2)
rigidbody.AddForce(1500, 0, 1500);
else
return;
}
public void AddForce2()
{
rigidbody.AddForce(100, 0,100);
}
}