Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [trigonometry]

A branch of mathematics that studies triangles and the relationships between their sides and the angles between these sides.

Filter by
Sorted by
Tagged with
0 votes
0 answers
20 views

Calculating yaw and pitch angles between up and forward vectors and direction vector

I have a transformation matrix and a direction vector, and am trying to calculate separate yaw, pitch, and roll angles between the matrix and the direction vector. I have already calculated forward, ...
user avatar
  • 1
1 vote
1 answer
40 views

reposition object in circle

As you can see on the image, I have a p1 and p2 objects with (x,y) coordinates which I know the values, and I know radius of all these circle objects. However, I want to calculate new position x,y ...
user avatar
  • 115
0 votes
0 answers
33 views

Moving Object "in or out" along the z axis using Sin(time) or Cos(time)

I am new to game development, and I have successfully moved an object in the x and y directions using Mathf.Sin(x) and Mathf.Cos(x). But I'm unable to move same object in the z-direction (in or out). ...
user avatar
  • 1
0 votes
1 answer
37 views

Is there an algorithm for a Joystick class that happens to be engine/framework independent?

I need to be able to get the given input's distance inside the joystick, bounded within -100% and 100% and an unbounded version of it, get the position of where the mouse's position projects to the ...
user avatar
  • 37
0 votes
0 answers
7 views

Why do we see such effect after Normalize X value from Position Node ( in World Space )? ( Unity Shader Graph ) [duplicate]

Why do we see such effect after normalize X coordiante from Position Node ( in World Space )? How does it works? What Normalize node do with X Coordinate? Do we normalize X value of vector or length ...
user avatar
0 votes
1 answer
61 views

Needs help on actually making the trigonometric function work as intended

...
user avatar
  • 37
0 votes
1 answer
41 views

Need help on finding the algorithm for getting the FlipX, Y and TextureRotation of my DirectionalAnimation class

I've created a class called DegreeAnimation, which is basically an implementation of my CustomAnimation class, but works with other directions, there are 2 constructors for this class, one where the ...
user avatar
  • 37
1 vote
1 answer
43 views

Trigonometry to move an arm around axis in 3D space

Hello I have a question about rotating a Rod hinged to a fixed point (so it swings all around), and targets. short form, I would like to know how to find a rotation that would point my rod (while ...
user avatar
1 vote
1 answer
80 views

Could you explain how this GameObject rotating around another GameObject works?

I'm just learning Unity and I follow a tutorial for a simple game which I want to build up from. I'm already mostly done with the course and at the end a "boss enemy" gets implemented. Its ...
user avatar
  • 13
0 votes
1 answer
189 views

Pygame : problem with calculating an angle between two points

I've been struggling to calculate the angle alpha between an object and a certain point M so that I can move that object to M. To calculate alpha, I'm using ...
user avatar
  • 216
0 votes
0 answers
88 views

How to decay sine or cosine wave so it takes one additional period to reach equilibrium

In many shmups, when enemies arrive, they accelerate onto screen, decelerate, and overshoot their static arrival position slightly, before backing up slowly to the position. This can be seen in many ...
user avatar
  • 1,297
0 votes
1 answer
27 views

How to find if a Ray intersects a Triangle Clockwise or Counter Clockwise

I have a Triangle with an intersecting Ray. How can I find out if the triangle's vertices are in a clockwise or counter clockwise rotation order with respect to the Ray?
user avatar
  • 101
1 vote
0 answers
45 views

How to unfold a spiral of balls?

I have a spiral made of balls. It's a spiral with equally distributed balls using the following formula (see link on math.stackexchange). This is how it looks like: Now, the spiral is rolling ...
user avatar
  • 2,502
1 vote
1 answer
59 views

How to add zombie arms to enemies in HTML canvas

I'm making a game with HTML canvas (not WEBGL). I have zombies that go to the center of the screen, but for now they are just circles. I want to give them two arms, like the arms players have in ...
user avatar
2 votes
1 answer
490 views

Any fast alternative to sine in GLSL?

Should I just use the built-in sin() function or my custom sine function? I'm concerned about performance here. I don't care about accuracy much here because I use it to just get wave effects in my ...
user avatar
0 votes
0 answers
42 views

Get direction vector of camera in voxel game

I am currently working on a Minecraft clone (a voxel game). The feature I'm working on is the ability to break blocks. I have a ray-casting/ray tracing algorithm for traversing the voxels, but the ...
user avatar
  • 101
2 votes
1 answer
60 views

Position Object always at the same distance of 2 other moving Objects?

I am making a procedural animation of a worm. I have already something working: (the green dot is the position Target, purple and red are the Head and the Tail of the Worm) I would like to add ...
user avatar
  • 223
0 votes
2 answers
235 views

When are oblique triangles used in game development?

I'm working on a project that explains how trigonometry is used in video games, and I need to mention oblique triangles. However, as far as I know, only right triangle diagrams are used in video games ...
user avatar
  • 3
4 votes
1 answer
387 views

space map generation

I am at the beginning of the creation of a space 4x and first of all i need to generate a galaxy of stars linked by connecting lines that changes in each new game, I'll add a few pictures to show what ...
user avatar
0 votes
1 answer
147 views

Convert GPS coordinates into Unity world space?

I am developing an AR application where a number of historical buildings are spawned around the player depending on his position when a target / QR Code is recognized. I know the Lat/Lon of these ...
user avatar
  • 103
1 vote
0 answers
42 views

How To Place Object On Ground Within Radius?

I'm using Unity and I'm building an object placement system where you'll be able to position objects around the player. I'd like to place objects flush with the ground, parallel to world up, even on ...
user avatar
0 votes
1 answer
48 views

3d points to rotation matrix of orientation

I have a vector in a 3D view, defined by a point p1(x1, y1, z1) and a rotation r1(x1, y1, z1). I can get a direction and a yaw. I need that vector to point another point p2 (x2, y2, z2). So I need a ...
user avatar
  • 1
0 votes
1 answer
435 views

Arc length between two angles

As I calculate the length of the arc (green) between two angles; I need a method like: arc_lenght (xpos, ypos, radius, ang1, ang2) { return arc_lenght }
user avatar
0 votes
0 answers
115 views

Pong paddle and deflection angles

I'm trying to make a pong clone and am having trouble grasping ball deflection. The way I'm approaching it is to increase the angle by how far the ball collides from the middle of the paddle. However, ...
user avatar
  • 123
2 votes
2 answers
270 views

Why are rotations in 2D game engines often counter-clockwise = positive systems?

I was looking over the API for a game engine a friend was developing in her spare time. She made the decision to make positive angles rotate in a clockwise direction. This immediately struck me as odd....
user avatar
  • 21
1 vote
1 answer
385 views

SIMD and Inverse Tangent

I'm calculating spherical UV coordinates in a loop, trying to get GCC to vectorize the code. Here's a compile-able example of what it looks like. ...
user avatar
  • 133
2 votes
1 answer
77 views

Triangular Metric

Given a point inside a unit equilateral triangle, how does one rotate it across the triangle perimeter? I.e. the triangle outline serving the same purpose as circle's circumference. That is actually a ...
user avatar
-1 votes
2 answers
125 views

I need help with calculating the angle my character is aiming at

So im doing this program where i want my hero to shoot to the direction its facing , but for this job to get done i need to calculate the angle my hero is facing with Math.atan2() , atleasts thats ...
user avatar
0 votes
0 answers
46 views

Adding spread to velocity Vector3D

I am trying to give an object a velocity spread (e.g. shotgun bullets or particle effect). ...
user avatar
1 vote
2 answers
118 views

How to get the Javascript equivalent of GameMaker's `hspeed` and `vspeed` given only `direction` and `speed`?

I'm using a NodeJS server to control NPC movement in a multiplayer game, and when they get too close to the edge of the room I need to reverse either the horizontal or vertical components of their ...
user avatar
1 vote
1 answer
56 views

Sum of FoV enemies

so what I need is to calculate the sum of players' Field of view. Put simple, In a 2d space, I want to check how much they cover (in degrees). So here are a couple of use cases to explain by example: ...
user avatar
0 votes
0 answers
41 views

Camera LookAt position with fixed screen position

I have a perspective "lookAt-type" camera. I'm trying to compute specific focus point of the camera, which should be placed in the middle of the screen: I also have a custom 3d point in world space, ...
user avatar
  • 1
0 votes
1 answer
61 views

Finding Closest of 8 Possible Angles to Theta Value

I'm working on creating a gesture recognition system, and I saw one simple implementation that isn't as accurate, but is really easy to implement. The idea is that you have a unit circle with the 8 ...
user avatar
0 votes
2 answers
126 views

How to panning camera on XZ axis with different angles

I have an Orthographic camera where the position is { x:0, y:100, z:0 } and is pointing/looking at { x:0, y:0, z:0 }. At this ...
user avatar
  • 115
1 vote
1 answer
35 views

Why does the first red-zone sometimes appear too close to the border in my battle-royale red-zone feature?

The Problem: If you've ever played or watched some gameplay of a battle royal game (like PUBG, for example), you'll always find an event during any battle called the red zone. Basically, at a ...
user avatar
0 votes
1 answer
171 views

Combine rotation XZ (horizontal) with YZ (vertical). Math formula

I'm trying to make a rotation vertically and horizontally around a point at the same time but I'm not able to combine both. I have this formula for the horizontal rotation: ...
user avatar
  • 115
1 vote
2 answers
235 views

Algorithm to produce a 2D 'flying through space' effect like the old Windows screen saver

I am old. My high school maths is a long way in my past and I am struggling to devise an algorithm that will produce a 2D 'flying through space' effect like the old Windows screen saver. It has— ...
user avatar
  • 11
0 votes
1 answer
33 views

Getting an object to move in another objects direction

I have a player and an enemy, both have x and y values, and I want to move the enemy to the player and have them 'touch' over time in a speed that I can determine, I tried calculating the angle ...
user avatar
  • 1
1 vote
1 answer
723 views

Move object at angle like a sine wave

I currently have this code, which moves an object in a straight line at an angle, where "dir" is the angle. velX = (float)(Math.cos(Math.toRadians(dir))) * speed; ...
user avatar
1 vote
1 answer
49 views

Aim/Scope Oscillation Algorithm

I have been struggling to find an algorithm to implement something that will make a direction oscillate within a cone constraint, in a helix-shaped fashion as in photo (it will always go back to the ...
user avatar
  • 705
2 votes
3 answers
263 views

Are there recursive variants for trigonometric functions to potentially improve performance?

This is perhaps a better question for mathematics SE, however, this deals more with the performance side of gaming, and software in general. When I say recursive function, I mean recurrence relation. ...
user avatar
  • 121
1 vote
2 answers
2k views

How can I correct an unwanted fisheye effect when drawing a scene with raycasting?

Hello I have a game using raycasting for the TI Nspire in Lua, and when the player faces a wall so that their degree they are facing is perpendicular to the length of the wall, I am having what is ...
user avatar
0 votes
0 answers
147 views

Calculate smooth transition between local space angles

I'm trying to calculate direction of moving character (to rotate it's animation). I have something like this: Character can have 4 cardinal directions. The rotation is calculated from the current ...
user avatar
0 votes
1 answer
48 views

Moving a point on a rotating sprite

I've been trying to get sprites to stay on a set point on another rotating sprite. At the moment, it's very inaccurate, the original position is wrong, and when the rotation is applied the sprite ...
user avatar
0 votes
0 answers
17 views

How to calculate Camera “correct” position and distance to Frame all my Scene? [duplicate]

Consider I have N dynamic points on my Scene, I would like to "frame" all them, with my Camera. How can i calculate (at runtime) Vector3 Position to correctly frame all my scene ? This is my idea: ...
user avatar
  • 817
1 vote
0 answers
580 views

Help with simple 2D Lens Flare effect

I'm currently trying to do a Lens Flare effect in a 2D game (Unity 3D) and i'm having problems with element positioning. This are my elements in hierarchy. "Camera Container" it's a GameObject, ...
user avatar
3 votes
2 answers
869 views

How to make a sprite blink with Libgdx?

I want to make a sprite blinking like this: ...
user avatar
  • 113
1 vote
1 answer
91 views

Why is my sprite moving 90 degrees to the right?

I have a sprite which i'm trying to move towards the top of the screen with the left and right buttons adjusting the heading. However when my heading = 0; my ...
user avatar
  • 23
0 votes
1 answer
670 views

Getting the current 'Forward' direction Vector values into code and how to use them?

Im having some trouble visualising how the maths works for this particular problem. Back when i coded in 2d only this was often a stumbling point for mine even when only dealing with an x and y axis. ...
user avatar
1 vote
2 answers
614 views

Why doesn't games use CORDIC for sin and cos?

If the game devs add CORDIC sin cos calculation to their games, their games will have much better FPS. Why do they use normal sin cos function (e.g. Math.sin) instead of CORDIC?
user avatar
  • 153