# Questions tagged [trigonometry]

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

147 questions
Filter by
Sorted by
Tagged with
33 views

### Calculating semicircle points of a scaled CapsuleCollider2D

I have a very simple code that draws the shape of a pre-defined capsule. It handles everything well, except the case when the GameObject to which the ...
38 views

### 2D orbit an orbiting body without ellipse

I have a monster (boss) that spawns a minion (m1) which orbits the boss. m1 can spawn its own minion (m2) which orbits m1. This creates a situation where m2 is orbiting m1 and m1 is orbiting the boss. ...
54 views

### How do I move a point in a specific direction in 3D Space?

I know how to move a point in a direction in 2D space it's like this: pointX += sin(angle) * movementSpeed; pointY += cos(angle) * movementSpeed; How do I do the ...
34 views

### Compensate bullets direction towards direction player is moving in

My new prototype is a top down shooting game, the player aims with the mouse and fires projectiles towards the mouse position, this works fine, when the player is standing still. When the player moves,...
66 views

### Why are my angle calculations not working properly?

I am using this code: ...
• 3
45 views

### Checking if I am looking through a window using angles

I am developing a mod for a game with a Lua api. I am trying to detect if I am looking through from behind a window when I shoot an enemy. For context, when I shoot through this window I apply a ...
37 views

### What is the relation between the magnitude of the cross product and dot product of two vectors?

If I have an equation: |A×B|=A.B What would be the angle in between A and B?
• 1
60 views

### Getting the scalar speed from an X and Y velocity [duplicate]

Given a Vector2(x,y) that represents an object's velocity, like so: ...
• 101
90 views

### How do I determine which pixel is under the cursor when looking at an equirectangular image through a camera?

I am working on a game. The camera is freely rotatable by the user. The background is displayed from an equirectangular image. I need to know which pixel of the background image is located under the ...
80 views

### How can i move actor's bounding box center in relative location in Unreal Engine 5?

This is my situation. I need align the center of the object (it's box) and the center of the scene component. I have only center of the box TVector type or FVector. How can i do it? ...
259 views

### Calculation of far distance plane based on yaw and pitch for a map renderer

I'm working on a vector map renderer. I want to calculate the far plane for a protective transformation, based on the yaw, pitch, roll and height of the camera above the map. Yaw (looking to the left ...
• 123
1 vote
183 views

### How to overshoot with direction_to

I've managed to get my sprite enemies shoot at the player with ...
• 301
89 views

### Well tuned orbit camera

I have been trying to make an orbit camera using glfw. I got a working solution which is as in the following. ...
• 1
216 views

### rotating a sprite with mouse cursor

i am learning how to make a 2d game using sdl and c++ and am currently trying to rotate the sprite so that is always facing the cursor, my game is set up with an entity component system, i have a ...
56 views

### How do I calculate the position and rotation where 3 given vectors would intersect 3 given points

I have 3 normalized directional vectors and 3 points. The 3 vectors are all attached to the same object, and I would like them to keep their angles relative to each other. I want to find a location ...
60 views

### How do I find two points on opposite sides of a circle where the angle of the first point's position is a percent of the whole circle?

I am trying to simulate sunrise/sunset with a linear gradient. I want the gradient to rotate around a circle whose diameter is the width of the screen with the center point being the very bottom ...
272 views

### How do I determine parallax scroll factor?

Implementing parallax scrolling is easy enough. This question is about improving its presentation. Hand-tuning some parallax scroll factors on multiple layers works, but parallax scrolling is meant to ...
• 191
239 views

### Finding the center of rotation in 3d knowing the start/end transformations

I need your help to solve a trigonometry problem, I'm unable to find any documentation about on the web... For convenience, I will use "transform" to indicate a position+orientation. Let's ...
2k views

### Using atan2 vs dot product to get an angle in 2D games

I have some confusion that I need to be cleared up about the atan2 function. I am making a game in Godot where a 2D ship rotates to face some object in space by ...
157 views

### Is there a generic formula to determine the angle of deflection off of a rectangle?

I have a perfect 2D system, with no friction, elasticity, etc. A ball is colliding with a rectangle. I know the angle of the motion of the ball in degrees. I want to figure out how said angle will ...
2k views

### How do I calculate the direction of an object relative to the another object's view

Here is a diagram of what I'm looking for: I am trying to find the math solution to determine where that smaller circle is relative to the bigger circle's view. I thought that the easiest way would ...
• 3
243 views

### How to rotate parent object to align child rotation with a separate game object?

I have attached two images with the desired start and end positions. The Brown Circle is the target rotation. The Orange Square is the parent (the black dot is the pivot point) and the Blue Rounded ...
89 views

### Tangent Space View Direction based factor value remap

I'm trying to setup a mask similar to what Fresnel produces. Unfortunately Fresnel gives pretty bad results at grazing angles so I ended up using this : ...
• 1,055
1 vote
87 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 ...
• 115
214 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). ...
• 1
103 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 ...
63 views

...
49 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 ...
1 vote
73 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 ...
• 37
1 vote
102 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 ...
• 13
902 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 ...
• 226
186 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 ...
• 1,307
62 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?
• 101
1 vote
91 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 ...
• 2,552
1 vote
86 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 ...
2k 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 ...
93 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 ...
• 101
142 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 ...
• 243
357 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 ...
• 103
1k 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 ...
• 41
579 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 ...
• 103
1 vote
74 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 ...
102 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 ...
• 1
728 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 }
• 101
201 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, ...
• 123
658 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....
• 31
1 vote
645 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. ...
• 133
91 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 ...