# Tag Info

19

Well in the simplest sense you have something like this. y |\ | \ m | \ s o | \ p v |(a) \ e (y)e |angle\ e m | \ d e | \ n | \ t | \ |__________\ x movement (x) The speed is however fast the enemy is, and you can determine how much they ...

11

In the image the red vector is the one we are trying to convert to cartesian, given angles phi & theta (in the description I will refer to the length of the vector as r, for radius of the sphere). So, the y-coordinate is the easy one, we know what the angle is between the red vector and the y-axis (phi), we just project the vector onto the y-axis; y=|...

11

The edit is reassuring. :) Okay, here's a straightforward update loop... Assuming when we fire the missile we initialize remainingFlightTime = 5f then... void UpdateMissile(float deltaTime) { remainingFlightTime -= deltaTime; // At the end of the trajectory, snap to target & explode. // The math will put us there anyway, but this saves // ...

10

if (Abs(Y) > Abs(x)) { if (Y < 0) { return "North"; } else { return "South"; } } else { if (X < 0) { return "West"; } else { return "East"; } }

9

It sounds like what you're looking for is either a transformation matrix, or a quaternion. Transformation Matrix I will just run down how to do this using a transformation matrix, since its probably the easier of the two to understand. A transformation matrix in 3D is a 4x4 matrix defined as follows: H = [xx, yx, zx, tx; xy, yy, zy, ty; xz, yz, ...

9

You could restart your time value every 2pi: if(time > 2*pi) time -= 2*pi; If is still okay to increase your time variable infinitely but the input for the sine is to large, just use fmod(time, 2*pi).

8

Because on the x87 (the x86's FPU) the fsin, fcos and fsincos instructions are much faster than software CORDIC. On other architectures such as PowerPC and ARM you usually can rely on an optimized implementation within the standard c library, the performance cost in normal use cases is still so minimal to not be worth the time re-implementing. fsin or fcos ...

5

You don't need to use any trigonometry for this. If you want the objects to be propelled straight away from the explosion, just give them a velocity proportional to the vector between the explosion point and the object's position. Additionally, you'd probably want to make objects near the center fly faster, so one approach would be to find the vector from ...

4

I'm not so sure if I understood your problem right, but I'll try to answer anyways. gluLookAt(), as its name implies, creates a view matrix for a camera, and takes three vectors as parameters. The first one is the camera's position. This is where your camera will be located. If you want your camera to rotate around itself, you most likely don't want this ...

4

The main reason behind the behavior you notice is that in the line motionDirection <- Math.Atan(newVector.Y / newVector.X); You set motionDirection to a radian measure, but then assume it is a degree measure on the following line. Since radian values are much smaller than degree values, this tends to just push the angle towards 0. The main reason your ...

4

Depending on how often you can have a "rigged" bounce, an incremental solution might be possible. For this example, I'll assume that: Collisions with the playing field boundary are always normal (angle in = angle out) Collisions with blocks can be 100% rigged whenever needed (angle out = arbitrary) Then each time you collide with a block, check whether ...

4

just my impression, but are you sure that you are not over-complicating things? Why invert the sine function at all, when you have the argument you have passed to it? That's precisely the value you are looking for, in your quest for trigonometric functions inversion... Just either cache the sin argument somewhere before applying the function to it, or ...

4

you should use ShapeRenderer for this. In your draw loop batch.begin(); // Draw sprites and stuff here so the line will be draw on them and not under batch.end(); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(1, 0, 0, 1); // Red line shapeRenderer.line(player.x, player.y, mouse.x, mouse.y); shapeRenderer.end(); This will let you draw a red ...

4

You can scatter points using... uniform random coordinates (prone to uneven clusters and gaps) or a shaken or jittered grid, where you start with a regular lattice of points, then add a small randomized offset to each (prevents big gaps/clusters, but can reveal its structure) or a Poisson distribution (some clever algorithms to generate this can be found ...

3

Luckily this is really easy. Just take the case of one particle and one explosion. Say the particle is at (5, 5) and the explosion is at (0, 0). Just by drawing this and looking at the picture, you can tell that the particle should move along the imaginary line between the origin and its location. So what you need is a vector that points from the explosion ...

3

You might want to briefly refresh your trigonometry (maybe by reading the overview at Wikipedia) if you're stuck. Your problem looks like this: Keeping that picture in mind, we can take essentially the same steps you described, but in a more mathematical form: As inputs, you have a centre point p0 (red) and an angle (blue) and a length (orange). As ...

3

You are using integers for all your numbers, unless you have a very specific purpose and know what you are doing, stick to floats for geometry. Your radius calculation is completely wrong, in createSphere you should do something like: for(float angle=0;angle<Math.PI;angle+=0.1){ createCircle(posx, posy, posz + Math.cos(angle)*height/2, FOV, Points, ...

3

A common approach to this problem, and many others, is to define "attachment points" (also called "hard points" or "nodes" or a million other things) to your model/sprite definitions. These are artist-defined locations on the model such as "left foot" or "head" or such. They are usually attached to the skeleton or other animation data (each frame for ...

3

Set endAngle to 2π. The spacing between points in radians is your angleIncrement. To get the Euclidean distance between two point the easiest way is calculating the distance between any two neighbouring points of the result. Also convert endAngle and angelIncrement to float.

3

sqrMagnitude is the vector length squared, but you need the vector lengths. Simple fix: return (Mathf.Acos ( scalar / Mathf.Sqrt (magnitude1 * magnitude2) ) * Mathf.Rad2Deg); Of course you could just use Unity's angle calculation function: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Angle.html

3

The other answer is wrong as of now, to correctly move along a plane based on a rotation you do the following: posX += Math.cos(rotation) * forwardSpeed + Math.sin(rotation) * strafeSpeed; posY -= -Math.cos(rotation) * strafeSpeed + Math.sin(rotation) * forwardSpeed; However I'd recommend making a variable for cos/sin that you update only when the ...

3

You get the path the same way you'd move the object when you shoot it. Just have a tight loop that simulates the movement of the object and keep track of the position every so often. Now you have a list of positions, if you draw a dot at each position, you have a dotted line the represents the path of the object if it were to be shot from that angle.

3

You're only getting angles in the top-right quadrant because you're taking the absolute value of dy & dx. The sign information is important for determining what quadrant atan2 should return. What I'd recommend instead is using vector normalization, rather than trigonometry. dx = touch.x - startPosFrontJoystick.x; dy = invY - startPosFrontJoystick.y; ...

3

Instead of atan(sf.y/sf.x), use atan(sf.y,sf.x). This works because it takes the sign into consideration. Dividing the two numbers loses the sign bit data, so which quadrant you are in is unknown. You can add fragColor=vec4(pr,f,0.0,1.0); to see what is going on. Also, if you want to fix your aspect ratio (the image stretching) add sf.y *= iResolution.y/...

3

The way this is usually handled in games is something called a transformation hierarchy. Here objects are arranged in a parent-child relationship, where each object's position, rotation, etc is specified in a local coordinate system relative to its parent's transformation. So to arrange square B so that it stays attached to the corner of square A, you'd set ...

3

It doesn't make a lot of sense to talk about algorithmic complexity (in the big-O sense) for the way we use atan2 in game development. Our inputs are always one fixed size (32 bit floats for the Mathf version), whereas complexity analysis looks at how the algorithm performs as the input gets arbitrarily large (not strictly in magnitude, but in how many bits ...

3

First of all, the FPS wouldn't be better. Most modern games are bottlenecked by the GPU mostly and are pretty OK with the CPU (often times only reaching a CPU usage of around 50% or less). Second, CORDIC is designed to be precise and easily implementable in the hardware. The sinus method (cosinus is basically a sinus with an offset) in most languages use ...

3

It looks like you're firing out your rays at evenly spaced angular intervals. rayf = facing + 30 ... x_ray = math.floor(x + (radius * math.cos(rayf * 3.141592653/180))) y_ray = math.floor(y - (radius * math.sin(rayf * 3.141592653/180))) ... rayf = rayf - (60/320) This makes a kind of intuitive sense - you want to sweep rays across the field of view - but ...

3

Why have we arrived at the convention that rotations should be counter-clockwise then, even in engines where positive y is down? Have we? Let us try CSS: const box = document.getElementById("box"); function step(timestamp) { let deg = timestamp/10; box.style.transform = "rotate(" + deg + "deg)"; window.requestAnimationFrame(step); } ...

Only top voted, non community-wiki answers of a minimum length are eligible