Hi,
i’m currently working on a arcanoid clone and have a problem:
What i want: To increase the speed of my ball relative to it’s movement-vector.
What i tried: A LOT. I crawled through so many answers here but got nothing to work.
Here is what i have:
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour
{
public bool hasStarted = false;
public bool tweaked;
public bool speedTweaked;
public float speed;
public Vector2 thrust = new Vector2 (0.5f, 0f);
void Update ()
{
if (!hasStarted) {
if (Input.GetMouseButtonDown (0)) {
hasStarted = true;
rigidbody2D.velocity = new Vector2 (3f, 10f);
}
if (!speedTweaked){
rigidbody2D.AddRelativeForce(thrust); // Does nothing lol
Debug.LogError("uhm..");
} else if (speedTweaked) {
rigidbody2D.AddRelativeForce(thrust); // Does also nothing omg
Debug.LogError("ok...");
}
}
}
void OnCollisionEnter2D (Collision2D col)
{
//add some randomness - this is also the cause of speed loss/ gain
Vector2 tweak = new Vector2 (Random.Range (-0.2f, 0.2f), Random.Range (-0.2f, 0.2f));
if (hasStarted) {
speed = rigidbody2D.velocity.magnitude;
Debug.Log (speed);
if (!tweaked) {
rigidbody2D.velocity += tweak;
Debug.Log ("Tweaked");
tweaked = true;
} else {
rigidbody2D.velocity -= tweak;
Debug.Log ("Tweaked");
tweaked = false;
}
if (speed <= 11) {
Debug.LogError ("Speed is under 10");
speedTweaked = false;
} else if (speed >= 12) {
Debug.LogError ("Speed is over 12");
speedTweaked = true;
}
}
}
}
I would appreciate some ideas.
Greetings