Tag Info

New answers tagged

0

You could either: post increment listNum prior to outputting listNum, assign your iter to listNum prior to outputting listNum, or instead of outputting listNum, just replace it with iter. The issue at hand is that your are not incrementing listNum.


-1

I get a simple geometry trick that will solve you problem. You actually have the position and the direction of the vehicle. So, with that information you can construct a plane. If vector position (Px,Py,Pz) and forward direction is (Dx,Dy,Dz) and the object´s position to check is (Ox,Oy,Oz) well, you plane's formula is: Dx*(Ox - Px) + Dy*(Oy - Py) ...


1

If two vectors point in the same direction, then their dot product is positive. If the point in opposite directions, there dot product is negative. If they are perpendicular, the dot product is zero. All we need to do is compare a vector from the car to the point and the car's forward vector: bool Car::isInfront(ngl::Vec2 _pos) { ngl::Vec2 fwdVec = ...


0

The idea is right, the execution however is chaotic. First of all "So far I have tried finding the vector perpendicular to its forward direction", you already seem to know the trick - swaping x,y and inverting one axis, but why you apply it to some random products of calculations? bool Car::isInfront(ngl::Vec2 _pos) { ngl::Vec2 fwdVec = ...


-1

In simple terms, there are two steps you'll need to take: Calculate the angle between the vehicle's position and the point's position. Compare that angle to the angle the vehicle is facing (the angle of the vehicle's forward vector). More specifically... Step 1 is easy: subtract one vector from the other, and use a trig function (often called something ...


1

Calculating the vector that points from a spring at point A = (x0, y0) to a spring at point B = (x1, y1) is simply: v = (x1 - x0, y1 - y0) Assuming no other forces acting on the player, then changing the player's velocity to some scalar multiple of v when they hit spring A would direct them to spring B. If another force like gravity is involved, then, ...


4

Distance d is the integral of velocity v (calculus). Velocity v is the integral of acceleration a. If you start at velocity s, and you travel for time t, then distance will be d = s * t + 1/2 * a * t^2. You will have two cases. If the object does not reach maxspeed, then you'll have one part where you're accelerating and one part when you're ...


0

The two equations you are looking for are: t * v_0 - 0.5 * a * t^2 = d v_0 - a * t = 0 where t is the elapsed time, v_0 is the optimal velocity, a is maximum acceleration, and d is the distance to the target. The trick is in interpreting these formula. First, we assume we are in 1D by applying and acceleration to zero any component of velocity that does ...


0

When acceleration a is constant, use the High School kinematics equations: v = u + a t delta-d = u t + a t ^2 / 2 v^2 - u^2 = 2 d (delta-d) delta-d = (v + u) / 2 t where: u is the unitial velocity (sic) v is the vinal velocity (sic) t is the elapsed time delta-d is the displacement from starting position to ending position.


0

Yes, you can perform simple binary search on region divisor vectors. If you pre-process and sort your divisors ccw(and you probably should), it is sublinear log(n) complexity for n regions (oposed to other answers with linear complexity), moreover it doesnt rely on inaccurate and slow functions like atan, in addition your regions does not need to be ...


0

If the sectors are of equal size then one approach would be to calculate the angle, divide by a full rotation and then multiply by the number or sectors: rad = atan2(x, y) normalised_angle = rad / (2 * pi) sector = (int)(normalised_angle * sector_count) For the example given in the question we would also require a π/4 offset to account for a quadrant ...


0

Yes. First calculate the matrix for the transformation that maps your custom quadrants to the standard quadrants numbering CCW from +ve X and +ve Y. Second apply this matrix to the point of interest (call it (x,y)) to get a mapped point in standard quadrant space (x',y'):. Now apply this formula to the resulting vector (x',y'): Quadrant = 1 + (1 - ...


2

In this case, what is wrong with comparisons? It's (in this case) pretty easy, just if(abs(x) > abs(y) if(x > 0) q = "q2"; else q = "q4"; else if(y > 0) q = "q1"; else q = "q3"; Alternatively, you could do something like (hopefully I'll get this right) angle = atan2(y, x); angle -= pi/4; // now (0,pi/2) is all Q1 quadrant = angle / (pi/2); ...


0

This is inspired by how OpenGL handles Cubemaps: (Pseudocode) vector = normalize(vector); if(abs(vector.x) > abs(vector.y)){ if(vector.x < 0) //Q1 else //Q3 }else{ if(vector.y < 0) //Q4 else //Q2 } (i hope you don't count this as "a bunch") Another way would be to calculate the angle which would involve a arctan and that ...


0

Does normalizing the vectors make a difference? @Jon: Good catch, normalizing "directionVector" seems to make the math work out (transform.forward is already normalized). So if you make this an answer I'll mark it as correct. If possible, could you elaborate on how normalizing the vector makes the math work out? I'm familiar with the concept of ...


2

if (Math.abs( angle) > mindelta ) transform.LookAt (currCustom); I think it depends on floating point math errors, I suggest to define a min angle (mindelta in my code example) inside wich, the turret doesn't move


0

I know this is an old question, but here is the answer for someone else stumbling over this problem. :) To get the Vector for the direction of the head you have to use, player.getEyeLocation().getDirection() Here is a working example of the code, you may have to play around with the multiplier to get the desired result. I also rewrote some of the ...


0

You can create a 2D rotation from a 3D one by just ignoring an axis (usually Z). Quaternion 3dRotation = Quaternion.Euler(myRotation); Quaternion 2dRotation = Quaternion(3dRotation.x, 3dRotation.y, 0.0f, 3dRotation.w); Using this method you can modify your rotation to ignore one or two axis. Or, you could use the same aproach when working with the ...


1

When you have a vector from your spaceship to the earth you can just calculate the projection of the vector onto your 'camera plane'. You can normalize this vector and you have the direction the arrow should point to. So you can use what you already have, rotate a vector and project it onto the 'camera plane'.


2

LookAt definition: public void LookAt(Transform target, Vector3 worldUp = Vector3.up); The default orientation, Vector3.up, it's not correct in your case (that's why the bullet is oriented upwards). Use: transform.LookAt(go.transform.position, Vector3.right);



Top 50 recent answers are included