What I want to do is instantiate (rather move out of a pool, but I feel that doesn’t make much difference) objects 2 and 3. I want their velocity vector to point them away from object 1 at a specific angle from object 1’s current direction, while keeping alpha and beta equal to each other and editable (not necessarily with a single number equal to the angle). I’d like object 2 and 3’s forward speeds to be the same as object 1’s. Is there a way to do this?
EDIT: I’m always keeping all the objects rotated at 0, 0, 0 and I’m working with 2D
If you have your direction or velocity vector for Object 1 (e.g. transform.forward or rigidbody.velocity) you can rotate that by doing something like this:
This would rotate it by -45 degrees on the Y axis but that can be changed to any axis depending on what you’re looking for. For Object2 you might use -45 degrees and for Object3 you might use +45 degrees.
Hey, thanks for replying. I’m sorry but could you elaborate on what this does exactly? I don’t know a lot about vector (let alone quaternion) math and multiplying a quaternion by a vector makes as much sense to me as fish climbing trees. Also I thought transform.forward returned a vector affected by rotation, not current movement? I hoped I didn’t have go for rotating, I’m trying to keep all the objects in their original rotation. I probably should have also cleared that I am working with 2D.
If it’s 2d it’s probably more straightforward. If you want to use movement you could use the rigidbody2d.velocity if your objects have rigid body components on them?
With that vector2 you can find the angle in degrees by doing:
Okay thanks for all that. It’s really late (here at least) and I don’t have enough energy to understand all the math you sent my way, so I’ll try and check it out tomorrow.
Yet I feel that there is a far more simple solution to this that I’m overlooking. All the objects have (2D) rigidbody components attached to them, so accessing their velocity is no problem. My real problem I think is finding the x and y in
object2.GetComponent<rigidbody2d>().velocity = new Vector2(obj1velocity.x + x, obj1velocity.y + y);
The issue I have arises from me wanting to do this for any and every direction in which object 1 might be heading and wanting object 2 and object 3 to have the same normalized velocity as object 1 (the latter of which I can live without).
Anyway I have no actual idea of how difficult the different functions are to compute, so if the code-complex solution is faster to process for the computer, I’m all for it.