AddForce 2D it's not working
I'm Instantiating an object and trying do add a force to it, I've tried a lot of ways but It's not working
void Update () {
float eixoX = Input.GetAxis("Horizontal");
Vector3 direcao = new Vector3(eixoX, 0, 0);
transform.Translate(direcao * Velocidade * Time.deltaTime);
if (Input.GetKeyDown("space"))
{
BalaPosition = new Vector3(this.transform.position.x, positionY, -0.1f);
BalaVoid();
}
}
void BalaVoid(){
GameObject BalaInstantiate = Instantiate(Bala, BalaPosition, this.transform.rotation);
BalaInstantiate.GetComponent<Rigidbody2D>()
.AddForce(new Vector2(velocidadeBala, velocidadeBala));
}
Comment
Hi @addoneto
What values are you using for velocidadeBala in your AddForce call? You also seem to add it also to both x and y axis...
Did you read this page: https://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html
Your answer
Follow this Question
Related Questions
C# Script - Erro CS8025: Parsing error 1 Answer
PlayerPrefs not debugging 1 Answer
How do I change the image of an SVG sprite? 0 Answers
Why am I getting this error "Object reference not set to an instance of an object" 1 Answer
[c sharp] why isn't my player dying when it touches the truck? 1 Answer