- Home /
Physics2D AddForce Direction Vector Issue
Hi Unity,
I'm trying to code a mechanic where an arrow (which rotates from 0 to 180 degrees and back again forever) points in a direction, and on pressing the space bar fires a ball in the arrow's pointed direction. I have 2 GameObjects at the head and foot of the arrow object, and I use their positions to make a direction vector. Unfortunately, the ball only fires in two directions: 45 degrees and 135 degrees. I've tried changing the vector to different values, but so long as the x and y of the vector aren't 0, it will only shoot in those two directions. I need this mechanic to be accurate to the nearest degree. Below is some of my code:
Rotating arrow and aim to change directional vector: transform.RotateAround(thing.transform.position, new Vector3(0, 0, 1), 1); transform.RotateAround(aim.transform.position, new Vector3(0, 0, 1), 1);
(pull's position and rotation remains relatively constant)
Sets and launches the direction of the ball: ballInitialForce = (arrowObject.aim.transform.position - arrowObject.pull.transform.position); GetComponent().AddForce(ballInitialForce);
Answer by catambroise · Jun 01, 2016 at 10:38 AM
Why not addforce(transform.forward force time.deltaTime); ?
I want the ball to bounce off the walls of the level in a breakout-like scenario, so I need the physics2D engine ins$$anonymous$$d of Transform.