Questions tagged [trigonometry]
A branch of mathematics that studies triangles and the relationships between their sides and the angles between these sides.
149 questions
14
votes
3
answers
25k
views
How do I make an entity move in a direction?
I have an Entity instance which is updated every game tick. Let's just assume that entity moves forward constantly. I'd like to be able to give the entity's angle ...
13
votes
2
answers
16k
views
How do I generate projectiles toward the mouse pointer? [duplicate]
I'm making a top-down space shooter where the player controls a ship and can aim and shoot using the mouse cursor. How can I fire bullets from the ship at the angle from the ship to the mouse cursor?
12
votes
1
answer
3k
views
How can I draw an arrow at the edge of the screen pointing to an object that is off screen?
I am wishing to do what is described in this topic:
http://www.allegro.cc/forums/print-thread/283220
I have attempted a variety of the methods mentioned here.
First I tried to use the method ...
9
votes
2
answers
711
views
Guided Missile with Constant Time
I'm building a game with players and missiles.
I want to fire a missile from P1 to P2. The missile should always take exactly five seconds to reach P2. The missile should also track P2. If P2 moves ...
8
votes
1
answer
17k
views
How to calculate a direction vector for camera?
I have a vector that describes change in movement, and I have a 3d-vector, m_rot, that describes a rotation given to an object.
I want to calculate a direction vector using both this data.
How to ...
8
votes
1
answer
4k
views
Spherical to Cartesian Coordinates
Well I'm reading the Frank's Luna DirectX10 book and, while I'm trying to understand the first demo, I found something that's not very clear at least for me. In the updateScene method, when I press A, ...
8
votes
2
answers
15k
views
How to rotate camera centered around the camera's position?
Currently I am using gluLook at like so:
...
7
votes
1
answer
10k
views
Raycasting "fisheye effect" question
Continuing my exploration of raycasting, I am very confused about how the correction of the fisheye effect works.
Looking at the screenshot below from the tutorial at permadi.com, the way I ...
5
votes
5
answers
11k
views
How to detect if object is moving in clockwise- or counterclockwise direction?
I've read this one, but I need more info: rotating an object from sourceAngle to destAngle, both 0-359, clockwise or counter clockwise?
I have a ball. The user is able to drag the ball in any ...
4
votes
3
answers
158
views
Propel entities at some angle (depending on explosion's position)
I have a 2D platformer. There are multiple particles that are just 1x1 colored pixels. Let's assume there are 256 particles laid out as a 16x16 cube. Say I popped an explosion right in the middle. All ...
4
votes
1
answer
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 ...
3
votes
6
answers
2k
views
How can I rotate a 16-bit signed integer vector?
I am trying to rotate a vector made of two signed 16-bit coordinates (-32768 to 32767). Using a LUT for sin/cos, I can use the standard method for rotating a vector:
...
3
votes
1
answer
169
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 ...
3
votes
2
answers
711
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....
3
votes
3
answers
3k
views
breakout game, computing optimal ricochet angle of a ball to get to a certain point
perhaps the title isn't clear so here is an explanation with a picture to better express my question
Consider the following breakout clone game
(source: ludumdare.com)
where the game is rigged to ...
3
votes
1
answer
309
views
Math behind drawing one game object relative to another?
Let's say I have a square (a) and I want to draw another square (b) that stays on one corner of the square (a).
Square (a) can rotate and move around the game world, what math would be used to keep ...
3
votes
1
answer
189
views
Super formula on shader
I'm using Shader-toy to experiment and try to learn a bit the shader science.
As exercise I wan to replicate some of the wikipedia math plots. I've started with a Super Formula.
What I want to ...
3
votes
2
answers
1k
views
How to make a sprite blink with Libgdx?
I want to make a sprite blinking like this:
...
3
votes
3
answers
296
views
Counter-clockwise angle limit
I'd like to limit rotation of an object, so I've written following snippet:
...
3
votes
1
answer
983
views
determine collision angle on a rotating body
update: new diagram and updated description
I have a contact listener set up to try and determine the side that a collision happened at relative to the a bodies rotation. One way to solve this is to ...
2
votes
1
answer
442
views
How do I make a sine wave without using an infinitely-increasing time value as input?
I have a basic understanding of sine wave generation. The problem I am facing is that as the input parameter for time gets larger, my sine wave falls apart and starts to look really ugly.
I'd like to ...
2
votes
1
answer
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 ...
2
votes
2
answers
6k
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 ...
2
votes
2
answers
1k
views
Asteroids Movement
I have been making an asteroids clone, in C#. However, the ship's movement is... not quite right.
My plan is this: there is a speed, and two directions, namely the direction the ship is facing (...
2
votes
1
answer
152
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 ...
2
votes
3
answers
319
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.
...
2
votes
3
answers
1k
views
Calculate target angle to a certain Vector
I'm developing a 3D game in LWJGL.
I have a player class and a monster class and I need the monster class to chase the player when the player is within a certain distance.
For that I have the monster ...
2
votes
1
answer
1k
views
Drawing a lines radiating from every angle using Bresenham line algorithm
I am trying to recreate a image like this
... or just each point
Using Bresenham line algorithm, but can't seem to able to do so.. The point i receive from my computation doesn't look like a like, ...
2
votes
1
answer
319
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 ...
2
votes
1
answer
93
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 ...
2
votes
1
answer
211
views
Translating yaw degrees into 2D movement
I've been hitting my head on the wall for a while with this, and I'm almost sure I'm overcomplicating it.
I have a variable for yaw in degrees (and also pitch and roll, but those should be irrelevant)...
2
votes
1
answer
3k
views
OpenGL Arc-Ball Camera Yaw Pitch GLM::Rotate
I'm currently working on a small Voxel-Editor Project. In the editor, I plan on using an Arc-Ball camera which rotate around the model. My camera is currently working but in an odd way. I can't seem ...
1
vote
2
answers
861
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?
1
vote
2
answers
512
views
Bullet entry Point around Player Object
I have a player rotating by the mouse and want the bullets line up with the player's gun. Right now they simply come from the point of the player and shoot in the direction of mouse. I just need the ...
1
vote
1
answer
977
views
Day/Night - Rotation from a sine wave
I recently found this question on stack exchange with a great answer that showed how to condense game time into a sine wave, where 1 = midday and -1 = midnight
Converting time of day into a smooth ...
1
vote
2
answers
339
views
atan2 : inversed result? (angle 180 is on the right side, angle 0 on the left side)
the result of the angle between my touch and the middle,bottom of the screen gives me 180 when the touch is on the right side of the screen, and 0 when it is on the left. I don't understand why...
<...
1
vote
1
answer
222
views
How to overshoot with direction_to
I've managed to get my sprite enemies shoot at the player with
...
1
vote
1
answer
1k
views
Unity Mathf.Atan2 algorithm complexity
using Unity5.5.1f;
using C#;
So I have a circle (2D) divided equally by 16 directions, and I also have a direction V which is different from the other 16.
In order to know which direction is the ...
1
vote
2
answers
2k
views
Find vector tangent to circle through a point
C2 and P1 are known points. Radius of circle C2 is also constant and known. I am trying to find point T to eventually construct line p1-t, which is tangent to circle c2.
I have made an attempt ...
1
vote
3
answers
3k
views
How to find the point on a hypotenuse divinging triangle into two right triangles?
Consider the following image:
Knowing the (x,y) coordinates of A, B, and C; how would one find the point D? D being the point where line CD cuts the triangle into two smaller right triangles?
I feel ...
1
vote
2
answers
547
views
How can I fix my sprite being rotated 90 degrees more than toward the mouse?
I am trying to get a Sprite in LibGDX to look at the player's mouse. Here's the code I have (mind you, I am using JRuby):
...
1
vote
1
answer
817
views
How do I find two points at an angle on opposite sides of a circle?
With reference to my previous question:
I'm using micklh's answer, which works perfectly. However, it calculates the gradient based on two points, a starting point and an ending point. I want to ...
1
vote
1
answer
209
views
Using circles to create a sphere
I've been working on creating spheres in a 3D space recently, and have successfully created cylinders. I've just run into a little problem. For some reason, my "Spheres" end up looking like very thick ...
1
vote
1
answer
95
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 ...
1
vote
1
answer
104
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 ...
1
vote
1
answer
1k
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;
...
1
vote
1
answer
56
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 ...
1
vote
1
answer
424
views
Is Physics a prerequisite to learn Unity3D
I have got a basic knowledge about the Unity 3D platform but I coding in Unity has not been that easy for me. For the simple reason I can see is, I cannot understand which function to use for what ...
1
vote
1
answer
75
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 ...
1
vote
1
answer
88
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 ...