Hello guys!
First of all. this is a big post, so I apologize for its size. Sorry for my bad grammar, its 3:00 am here and I’m sleepy.
I’m expanding my skill mechanic and I’ve tried to use both quaternions and affine transformations/rotation matrices to do the job, using my mathematical knowledge I’ve learned long ago, on my university.
Based on the facts that quaternions are 4D vectors extended from i-numbers that should be normalized before multiply them with any vectors or generate any kind of rotation matrix (because we must bring it back to the unit sphere in the 3D Euclidean space) and the multiplication between two vectors results in a perpendicular vector (result of a cross product) that not necessarily is a unit vector and should be normalized, among other things, I tried to make an actor, captured by black hole skill, initiate an elliptic orbit around its captor.
Elliptic orbits were calculated, initially, based on the ellipse parametric equation (the FVector NextLocation = (…) part, lines 468 - 477). As you can see in the video, it works relatively well, except for ONE PROBLEM: the orbiting actor was supposed to start orbiting in the position (SkillLocation.X + radius * Cos(XYAngle), SkillLocation.Y + radius * Sin(XYAngle), SkillLocation.Z), the XYAngle is calculated in the ABlackHoleSkill::GenerateOrbitData() method), but, as you can see, is way off, In the video, the orange line is used to mark the (constantcos(0),0,0), the magenta to mark the (0,constantc sin(90),0), the cyan marking the (constantccos(180),0,0), and the yellow marking the (0,constantcsin(270),0), for visual debug purpose, as well the white line, marking the vector point to the orbiting actor initial location. I’d appreciate if someone tell me my mistake here.
Second, I tried, inside the GenerateOrbitData method, to project the PullDirection vector on the planes XY XZ and YZ, and to find the angles between these projections and the skill’s forward and right vectors, respectively. Once I’ve got these values, I increased them by a specific value and used them on rotation matrices (basically making use of Euler angles), but I didn’t get the result I was expecting. I just left the Z axis rotation matrix uncommented, to rotate the orbiting actor on the XY plane, like the parametric equation used ealier. I tried this to make the captured actor orbit not only on XY plane, but any plane, around the skill.
Here is the video: https://www.youtube.com/watch?v=aZnx…ature=youtu.be
And here is the code:
.h:
https://pastebin.com/tiBjeWpX
.cpp
https://pastebin.com/d705gbts
At the end of the video, you can see that the build just failed, ignore that, the FMatrix::TransformVector4() doesn’t work neither.
Also, in the GenerateOrbitData(), I’m using a quaternion to rotate the orbiting actor around its own center, ignore it for now.
Can you guys tell me my mistakes? Also, to avoid a gimbal lock (because I’m using Euler angles), can you tell how to do what I’m trying to do, instead using rotation matrices?
Thanks! =)