Trying to fix a (yes temporary) problem with the Ball in block breaker, specifically trying to apply a constant lateral force to prevent ball from getting stuck in an endless up/down loop. ( I realize this is no problem once blocks break)
For some reason I have no problem applying a torque but a force is proving difficult. I’m sure I am missing something but no matter where I put the variable declaration, I seem to get an error trying to specify a Vector2 x,y force. It is acting like I am not using Vector2 correctly.
the Vector2 variable addedForce is the forece I want to add ( eg. 0.2,0.0)
using UnityEngine;
using System.Collections;
public class Ball : MonoBehaviour {
public Paddle paddle;
private Vector3 paddleToBallVector;
private bool hasStarted= false;// has the game started?
private Vector2 addedForce;
void Start () {
paddleToBallVector = this.transform.position - paddle.transform.position; //the offset to paddle
print (paddleToBallVector.y);
13 addedForce = (0.02,0.0); // how much sideways force to add to prevent stalling loop of ball
}
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
}
}
}
}
error message is:
Assets/Scripts/Ball.cs(13,35): error CS1026: Unexpected symbol ,', expecting
)’
I’m sorry this post came out so messy