Character Jump Arc? Alter the Y axis during Vector3.MoveTowards? - unity3d

I'm trying to make a character jump between two points. The two points are varying distances apart, and at different heights.
I have the character moving from point to point using Vector3.MoveTowards in a IEnumerator. But how can I make modify the Y axis so that the character moves in a curved path to appear as if jumping?
The character needs to land exactly at each point, so I cannot use physics.
Thanks! :-)
Image Example
Extra bonus points if you can adjust where you want the peak of the jump to occur (so the curve isn't perfectly circular, but more like an arc) E.g. so that the peak of the jump is closer to destination.

Looking at your given image, I would suggest using a projectile motion's equation to calculate the path between the source and destination in a given time with a given start velocity(Vo) and given angle (theta).
In case you are not familiar with projectile equation, have a look at here:
https://en.wikipedia.org/wiki/Projectile_motion
In the Displacement section you'll find 2 equations like this:
x = Vo * T * cos(theta)
y = Vo * T * sin(theta) - 0.5 * g * pow(T,2)
So, in Update function don't move the object directly towards the target, rather take temporary targets along the projectile motion, which you can calculate using the above two equations. You can then use,
Vector3.MoveTowards(curPosition,new Vector3(x,y,0),step);
Considering, the z value is 0.

Related

Is it posssible to find an x/y coordinate without Angles? i need this for a target locator in a Scratch Program

My scratch project:https://scratch.mit.edu/projects/657133771
i need a triangulation/trilateralation equation for a target locator. otherwise the tank is just stupid.
Try using the Distance Formula (Pythagorean Theorem) to calculate the distance between points. Simply use:
distance = sqrt( (x2-x1)^2 + (y2-y1)^2 )
Make the x and y change at the same time. It will give an angle effect, and your sprite does not have to turn. Not exactly a formula, but if you match up the x and y changes in the right way, you get different angles.

Convert coordinate from one world coordinate system to object coordinate system

I am more interested in the mathematics behind this problem, but am using matlab to try and solve this problem. I have an object, positioned using the world coordinate system at (Wx, Wy, Wz)
I would like to calculate the coordinates of this point using the object coordinate system (Ox, Oy, Oz)
To do this, I first need to calculate the axes of the object coordinate system.
Step 1 is to find the Normal (Nx, Ny, Nz)
(assuming that this is not the world z-axis). My object has a yaw, pitch and roll angle applied so I need to find my normal relative to this.
To do this I use a rotational matrix and perform the operations in the order stated above.
Step 2 is to calculate the arbitrary axes.
If abs(Nx < 1/64) and abs(Ny < 1/64)
(Axx, Axy, Axz) = cross product of world y-axis (0,1,0) and the Normal
else
(Axx, Axy, Axz) = cross product of world z-axis (0,0,1) and the Normal
(Ayx, Ayy, Ayz) = cross product of N and Ax
I then scale my arbitrary axes by dividing by the sqrt of the sum of the squares.
Step 3 - Transform the coordinate
To transform the coordinate you point multiply the initial coordinate by each of the axes.
Ox = Wx * Axx + Wy * Axy + Wz * Axz
Oy = Wx * Ayx + Wy * Ayy + Wz * Ayz
Oz = Wx * Nx + Wy * Ny + Wz * Nz
DXF for autocad takes the object coordinates, the Normal vector and a rotation about the normal vector.
This appears to be working reasonable well at positioning the coordinate, but with some issues:
When I use the method above, I find that sometimes my objects are rotated 180 degrees. Digging into this, sometimes the Arbitrary x-axis is negative, sometimes it is positive. This may account for some objects being rotated, but Autocad does not actually reference this Ax vector. It calculates it. This means that I may have to correct this with a rotation about the normal, but I do not what it to always apply (I cannot simply look for a negative value and rotate if negative, as sometimes the object is required to be placed in this direction).I do not know how to overcome this.
If I apply a roll angle to the object and work through this process, the roll angle is not applied correctly. Instead this appears to translate this angle as an Yaw and Site change, but not actually the intended rotation. I cannot see what I have done using the above formula.

How to obtain projections for a matrix along a specific line?

Given parametrization of points on line L(t,θ) is
x(s):= t cos θ − s sin θ
y(s):= t sin θ + s cos θ, where t is the distance from the origin to the line at the angle θ from x-axis, and s is some point on the line.
How to take projections of image Img at this line L(t,θ) with specific step size s. Using this I have to implement a radon transform further.
My question is how to define step size s and value of t ?
Also, do I need to rotate Img or without rotation is it possible?
Please help.
I suggest you have a look at the multiple Open source software that are around.
In tomography, rotating the image is the same as rotating the machine around, so you could change the source/detector position per angle and then compute the line that joins them. Then, the step size is up to you. Research has shown (I have tested this) that a good value is s=pixel_size/2 or 0.5 if you are working in standard pixels.
If you are doing 2D parallel beam then you can forget about all the geometric transformations that need to be performed and generate projections by using imrotate. If you are using fan beam or cone beam, then the code gets a bit more complicated.

Azimuth and Elevation from one moving object to another, relative to first object's orientation

I have two moving objects with position and orientation data (Euler Angles, Quaternions) relative to ECI coordinate frame. I would like to calculate AZ/EL from what I'm guessing is the "body frame" of the first object. I have attempted to convert both objects into the body frame through rotation matrices (X-Y-Z and Z-Y-X rotation sequence) and calculate a target vector AZ/EL this way but have not had success. I've also tried to get body frame positions and calculate the body axis/angles and convert back to Eulers (relative to body frame). I'm never sure how the coordinate system axes I'm supposedly creating are aligned along my object.
I have found a couple other questions like this answered with Quaternion solutions so that may be the best path to take, however my Quaternion background is weak at best and I fail to see how the computations given result in a target vector.
Any advice would be much appreciated and I'm happy to share my progress/experiences going forward.
get the current NEH transform matrix for the moving object
you must know position and at least two directions from North,East,Height(Up or Altitude) of the moving object otherwise is your problem unsolvable no matter what. This matrix/frame is called NEH (X=North,Y=East,Z=Height) or sometimes also ENU (X=East,Y=North,Z=Up). Look here transform matrix anatomy and here Earth's NEH construction and change the position and radius to match your moving object.
convert point P0 from GCS (global coordinate system) to NEH
simply: P1=Inverse(NEH)*P0 where P1 is now in NEH LCS (Local coordinate system). Both P0,P1 are in homogenous coordinates { x,y,z,w=1 } to allow multiplications with 4x4 matrix so you can compute azimut and elevation directly from it:
Azimut=atanxy(P1.x,P1.y);
Elevation=atan(P1.z/sqrt((P1.x*P1.x)+(P1.y*P1.y)));
where atanxy is mine atan2 (4 quadrant atan) first is dx then dy. I think atan2 in matlab has it in reverse.
[Notes]
Always visually check all frames (especially NEH). Just draw the 3 axises as lines of some length to validate if the result is correct. It should look like on image, just different color for each axis. You can move to next point only if NEH is OK !!!
Check atan2/atanxy operands order and also check goniometric functions units (rad,deg) to avoid confusions.

Matlab matrix translation and rotation multiple times

I have a map of individual trees from a forest stored as x,y points in a matrix. I call it fixedPositions. It's cartesian and (0,0) is the origin.
Given a velocity and a heading, i.e. .5 m/s and 60 degrees (2 o'clock equivalent on a watch), how do I rotate the x,y points, so that the new origin is centered at (.5cos(60),.5sin(60)) and 60 degrees is now at the top of the screen?
Then if I were to give you another heading and speed, i.e. 0 degrees and 2m/s, it should calculate it from the last point, not the original fixedPositions origin.
I've wasted my day trying to figure this out. I wish I took matrix algebra but I'm at a loss.
I tried doing cos(30) and even those wouldn't compute correctly, which after an hour I realize were in radians.
I'd try the following: In your object, you already have a property heading. Now you add another property, currentPosition (an maybe rename them to heading_robot and currentPos_robot). heading as well as currentPosition should always be relative to the original coordinate system
Then you add a new method, updatePosition that takes (newHeading, distance) as input. This method will update both heading and currentPosition, by first adding the angle in newHeading to the angle in heading, after which you update currentPosition by adding [distance*cos(heading),distance*sin(heading)] (check for signs of sin/cos here!) to the old value of currentPosition.
Finally, to get the view of the landscape (i.e. apparentPositions), you run bsxfun(#minus,fixedPositions,currentPosition) to move the origin to where the robot is at this moment, and then you multiply with the 2D rotation matrix using the angle stored in heading.
You just first translate the coordinates (-0.5cos(60),-0.5sin(60)) to take the origin to your target point.
Then rotate by multiplying the coordinates by a rotation matrix.
Of course, most programming languages use radians as angle units, so that instead of 60 you must enter 60 * PI / 180