New answers tagged

1

You are fixing the time to 10(seconds?), so it will always takke it 10 seconds to reach its target. So if its a short distance, the bullet will move very slow and over a long distance the bullet will move very fast. So you need to set the time to (distance)/(velocity).


2

First , your polarToComponent(magnitude, angle) { return { x: magnitude * Math.cos(angle), y: magnitude * Math.sin(angle) }; Called for each ball at start time, introduce a numeric error. So you must calculate the total velocity before starting simulation and compare with that instead of 30. Second your function checkCollisions() ...


1

You can't get the "right" vector from just a "forward" vector. Any particular "forward" vector could have an infinite number of different legal "up" and "right" vectors. For example, if I am looking forward along the z axis forwardVector = vec3(0,0,1), then I could have up be along the y axis upVector = vec3(0,1,0) and right therefore be along the x axis ...


4

I suggest changing your API so that it tells you explicitly whether the lines intersect: public static bool LineIntersectionPoint(Vector2 startPoint1, Vector2 endPoint1, Vector2 startPoint2, Vector2 endPoint2, out Vector2 intersectionPoint) { // ... if (delta == 0) ...


3

You can return a Nullable Vector2? public static Vector2? LineIntersectionPoint(Vector2 startPoint1, Vector2 endPoint1, Vector2 startPoint2, Vector2 endPoint2) { // Get A,B,C of first line - points : startPoint1 to endPoint1 float A1 = endPoint1.y - startPoint1.y; float B1 = startPoint1.x - endPoint1.x; float C1 = A1 * startPoint1.x + B1 * ...


0

If you want to get position A relative to B, you just need to substract them, like you were doing. If you want to make use of the methods, you can use the method "sub": https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector2.html#sub-com.badlogic.gdx.math.Vector2- Vector2 relative = A.sub(B); //contains the position of A relative ...


0

Given points A, B and C of a triangle, the normal of the triangle is the cross product AB×AC (or possibly AC×AB depending on the vertex order). If the point on the triangle is M and the point towards which to look is P, you then have an infinite number of rotations that cause AB×AC to be in the direction of MP. The shortest rotation of them all can be ...


2

Here's a Unity-specific option in the same vein as sam hocevar's answer: Vector3 GetRandomUnitPerpendicular(Vector3 v) { float angle = Random.Range(0, Mathf.PI * 2f); // Generate a uniformly-distributed unit vector in the XY plane. Vector3 inPlane = new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0f); // Rotate the vector into the plane ...


0

You are looking for any vector that is completely in the plane described by a normal vector. Let's call your normal vector n, and the result vector (what you want to calculate) r. You know something about the relationship between the two vectors, namely that their dot product must be 0. That's one equation, but you have 3 unknowns here (the x, y, and z ...


0

We know that the cross product of two vectors in 3-dimensional space is another vector which is orthogonal to both original vectors. Given a vector which starts at the origin, we can just pick any random vector which starts at the origin to do the cross-product against. Since the cross-product produces a vector which is orthogonal to both, and we picked a ...


1

I would do the following: have your vector u (ensure it’s normalised) pick an orthogonal vector v using any existing method (ensure it’s normalised) pick a random angle α a good random unit vector is therefore: v·cos(α) + (u × v)·sin(α) If you wish your vector to also have random length, you can then multiply it by a random number, or possibly by the ...


0

What is happening is that your "nextPoint" vector is not actually describing a point in world space; it is describing a direction and distance away from your starting point. So in order to get the world space position of where this vector is pointing to, take the world space position of your starting point, then add your offset vector to it: nextPoint = ...



Top 50 recent answers are included