Hot answers tagged

5

I'm a bit skeptical of using atan here, because the tangent ratio shoots off to infinity at certain angles, and may lead to numerical errors (even outside of the undefined/divide by zero case for shooting straight up/down). Using the formulae worked out in this answer, we can parametrize this in terms of the (initially unknown) time to impact, T, using the ...


3

Don't use Euler angles for that, you'll get in trouble with a Gimbal lock in some situation and you'll be clueless about what the angles will be doing. Instead, use Quaternions to both represent your current rotation and any changes to it. Quaternions are often used to describe a rotation in 3d space by encoding: a rotation axis (in form of a 3-...


3

Don't use Euler angles for that, you'll get in trouble with a Gimbal lock in some situation and you'll be clueless about what the angles will be doing. I would suggest you use a space for your object, i.e. the option 2 you suggest. To make a space you need 3 vectors: the front vector, which represent the front of your model and the heading, and the side, ...


2

This might not be your only issue but I noticed you're using sin and cos with degrees. You must first convert your angles to radians for those functions to work properly (read "Parameters" here): #define PI 3.14159265 std::pair<int,int> endpoint(double angle, int x1 , int y1, int length) { // ... double x2 = x1 + (length * cos(angle * PI / ...


2

Let s1 and s2 the segments, so you can calculate the angle of each using atan2(s.p1.y-s.p2.y,s.p1.x-s.p2.x) where p1 and p2 are the two points defining s; double theta1 = Math.atan2(s1.p1.y-s1.p2.y,s1.p1.x-s1.p2.x); double theta2 = Math.atan2(s2.p1.y-s2.p2.y,s2.p1.x-s2.p2.x); Taking the absolute value of the difference, you get the angle between the ...


2

It works via repeated Rotations, you begin mentally with the Vector {1,0,0} then you rotate it along the Y-Axis the length of the vector is just one so you can get the new coordinates simply by evaluating sin and cos (of the angle along the Y-Axis), as their pair represents points on a circle hence rotating but you are rotating in another direction than in ...


2

First let's look at how to convert an angle (the yaw-angle) into a vector in two-dimensional space: As you can see the y-value is the sine of the angle and the x-value is the cosine of the angle. direction.x = 1 * cosYaw; direction.y = 1 * sinYaw; Now what happens when we add a 3rd dimension and rotate all of that around the x-axis by a new angle (...


2

Summary My recommendation is to compute a restorative torque to apply to the object. This is physically more accurate than setting the velocity directly, and the simulation will be better behaved. This solution should also work for any launch angle. Below is a gif of this method at work stabilizing arrows launched from a car. Restorative Torque This ...


1

Naivety indeed! My image_angle = direction; code was on my bullet creation event. An alarm on my ship object is what creates the bullets, then sets their direction. The creation code on my bullet object was being called before the new direction had been set. I removed the creation code from my bullet and added the following code to my ship's alarm. bullet1 =...


1

Thanks to DMGregory, I now have a C# extension script which can be used for this. Most recent version can be found on GitHub. using UnityEngine; public static class Rigidbody2DExtensions { /// <summary> /// Applies the force to the Rigidbody2D such that it will land, if unobstructed, at the target position. The arch [0, 1] determines the ...


1

I'm not well-versed in three.js, but it looks like you should be able to do it like this... var view = new THREE.Vector3(); view.subVectors(controls.getObject().position, players[i].mesh.position); var inverse = players[i].mesh.quaternion.clone(); inverse.inverse(); view.applyQuaternion(inverse); // view is now a direction in the object's local space. ...


1

I happened to be writing a script that draws this kind of preview arc for a workshop I'm putting together: (Public domain art assets courtesy of Kenney) Here's the script: [RequireComponent(typeof(LineRenderer))] public class PreviewArc : MonoBehaviour { public float predictionSeconds = 4f; public int subdivisionCount = 20; LineRenderer ...


1

There's a great writeup on this process by Mike Day: https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2012/07/euler-angles1.pdf It is also now implemented in glm, as of version 0.9.7.0, 02/08/2015. Check out the implementation. To understand the math, you should look at the values that are in your rotation matrix. In addition, you have to know ...



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