Dragon doesn't always face to the target point
tschaffter opened this issue · 6 comments
I set a station and traveled to it successively from a position at the North, South, West, and East of the station. Each time the dragon was facing correctly to the station point. However, the dragon is not facing the destination point when leaving from North-East, South-East, South-West, and North-West.
The station in the image below is located on the top of the emerald block.
I'll try to work on this issue during the next days to see if there is a fix for this.
In theory, you just set the yaw for the dragon and that's what we are already doing. I think, there might be an overflow (360+x =x) though since the calculation works, but only for some directions.
The basic calculation should be correct, that's why I did not fix it yet.
@tschaffter @NoChanceSD @Phiwa I'm working on this.
First I'll contact my mathematical consultant for a algorithm to calculate
direction change between (x+5, y+5) and (x, y) in realtime during the movement.
And try to update it for a flying dragon.
@Phiwa She said something like
old = 0, new = 1
tanθ = (y1-y0) / (x1-x0)
arctan
result - 180 + 360
Then can get a value for forward direction angle.
Although I didn't understand one letter in the formula(my math sucks)
This should work.
My idea is track this in realtime if performance is allowed or play some tricks.
In the initial I use station target location and current location to calculate first direction.
When future updates, the first target location should be nearest station key frame.
Not sure if Minecraft even can adjust 3D angle (720 in 3D space).
But this is basically what we are already doing...
We are recalculating the new direction on each server tick.
Please take a look at the current implementation before planning big changes.
You can find it in https://github.com/Phiwa/DragonTravel/blob/master/src/main/java/eu/phiwa/dragontravel/nms/v1_13_R1/RyeDragon.java (lined 82-104) or in other packages, depending on the version of CB/Spigot).