I cant reproduce it 100% of the times, but i have made the ball enter and endless loop bouncing up and down, even with the fix that was explained.
I tried playing with the angles of twek variable but nothing so far…
any ideas?
I cant reproduce it 100% of the times, but i have made the ball enter and endless loop bouncing up and down, even with the fix that was explained.
I tried playing with the angles of twek variable but nothing so far…
any ideas?
yes I noticed that. It happens even faster if you give the ball friction it seems. we need to add some sort of a lateral force like a wind field.
Did you manage to fix it?
yes , here is a link to add a force vector. I am discussing a problem getting it to work in this thread, basically I forgot to “new” the Vector2 variable but otherwise the code is there and it works!
Thanks for your reply. I tried what you suggested but for some weird reason the ball still entered and endless loop.
However i solved it in a more “simple” maybe “ugly” way.
I just added a small sphere (so it bounces) on the cornes, so, only part of the sphere is in the play field, that way it doesnt seem to get stuck.
Anyway, thank you for the reply!
that’ll work, btw you may just need to increase the amount of force … Really though, its not a problem , when we get to the place where the bricks break then they only stay in that one oscillation until the brick breaks!
ok here it is , I had to increase force to 0.5 (edited) AND add it every frame (using an else on if (!= gameStarted) also on ball material can set friction to 1 and can see ball spin change
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
private Paddle paddle;
private Vector3 paddleToBallVector;
private bool hasStarted= false;// has the game started?
private Vector2 addedForce = new Vector2 (1f, 0.0f);
// how much sideways force to add to prevent stalling loop of ball
void Start () {
paddle = GameObject.FindObjectOfType<Paddle>();
paddleToBallVector = this.transform.position - paddle.transform.position; //the offset to paddle
print (paddleToBallVector.y);
}
void Update () {
if (!hasStarted){// do while game not started
this.transform.position = paddle.transform.position + paddleToBallVector;//locks ball relative to paddle
if (Input.GetMouseButtonDown (0)){
print ("left mouse button clicked so Launch Ball!");
this.rigidbody2D.velocity = new Vector2 (2f, 10f);//shoot ball up
this.rigidbody2D.AddForce(addedForce, ForceMode2D.Force);
this.rigidbody2D.AddTorque(0.6f,ForceMode2D.Impulse);
hasStarted = true;//game has started
}
}
else {
this.rigidbody2D.AddForce(addedForce, ForceMode2D.Force);// adlateral push every frame if started
}
}
}
Thank you for the help!
ok shoot it keeps adding force over and over and it slowly builds up after a while the ball keeps looping around bouncing off the right wall. SOoooo I should put this force back into start only OR it looks like some later lesson is going to fix this for us so I’ll just wait on it