Hot answers tagged

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.


2

if (Math.abs( angle) > mindelta ) transform.LookAt (currCustom); I think it depends on floating point math errors, I suggest to define a min angle (mindelta in my code example) inside wich, the turret doesn't move


2

You wil want to subtract the touch with the ref point: //180 is inversed? 180 is when touch is on the right side... let dy = (touch.y - refPoint.y) //opposite let dx = (touch.x - refPoint.x) //adjacent This results in the (dx, dy) vector being from the refPoint to the touch point (as you would expect).


2

You're not taking into account the inverted Y axis in comparison to the normal X axis in most (maybe all?) programming languages. The top left corner of the screen is (0, 0), and is positive in the right and down directions. So if the bottom middle of your screen is, for example, (300, 400), and you click at (0, 400), then your triangle will be a first ...


2

Byte56's answer is very good, especially for the example image given where simulating the movement of each "ball" in the line will work well. I'll give you an alternative idea however which might work better, or might be easier to implement if you are trying to work with a dashed line (with or without animation), something like -- -- -- -- Calculate the ...


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 ...


2

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 ...


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 / ...


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 ...


1

JSON Philipp makes a good point about JSON. It is human readable and makes debugging network code easy. If you have no experience in programming network code, this would be the way to go. Yes, there is a lot of overhead by using JSON, but for small to medium data transfers, it should be more than enough. And like Alexandre Vaillancourt said, you can always ...


1

Your drawings seem inconclusive with respect to axis names and signs. Just going by the first illustration, you could say approximately: _playerSpeedY = 2 _playerSpeedX = -1 // going to the left, negative! radians = atan2(_playerSpeedY, _playerSpeedX) degrees = radians * 57.29577951 I get radians = 2.0344439357957027 and degrees = 116.56505117080718 ...



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