Rotation Problems

Blitz3D Forums/Blitz3D Beginners Area/Rotation Problems

Black Hydra(Posted 2004) [#1]
I've looked over this code for awhile now and I can't figure out what I've done wrong. Obviously my formula I am using isn't good as this code just doesn't work.

I'm trying to get the camera (attatched to the camerapivot entity) to stay behind the object, but I want it to reach that point slowly, that is, I don't want it locked behind my object. The code works fine, except when my object and my camera are in a particular angle range and then everything screws up. I assume this angle range is when one object is close to 360 and the other is close to 0 as in: Object Angle = 359, CameraPivot Angle = 2. I've tried many different means to get them to round inbetween these values but I still have the same problem.

If anyone knows of a good way to have the camera follow behind an object with some speed lag then be my guest. If you know what I've done wrong in my formula's then I'd be even more grateful.

Here is the movement code as is:

M# = User\Manuever
;Movement style using mouse speed rather than position
YAng# = WrapAngle(EntityYaw(User\ObjectNum)-M#*MouseXSpeed())
XAng# = WrapAngle(EntityPitch(User\ObjectNum)+M#*MouseYSpeed())
If XAng# > 70 And XAng# < 180 Then XAng# = 70
If XAng# < 290 And XAng# > 180 Then XAng# = 290
PitchAverage# = ((EntityPitch(User\ObjectNum)*.5)+(EntityPitch(User\CameraPivot)*1.5))/2
YawAverage# = ((EntityYaw(User\ObjectNum)*.5)+(EntityYaw(User\CameraPivot)*1.5))/2
;You must also take the possible negative average of the value if the shortest distance would cross
;the 360//0 degree connection
If EntityPitch(User\CameraPivot) > 180
NPitchAverage# = ((EntityPitch(User\ObjectNum)*.5)+(EntityPitch(User\CameraPivot)-360)*1.5)/2
Else
NPitchAverage# = ((EntityPitch(User\ObjectNum)*.5)+(360-EntityPitch(User\CameraPivot))*1.5)/2
EndIf
If EntityYaw(User\CameraPivot) > 180
NYawAverage# = ((EntityYaw(User\ObjectNum)*.5)+(EntityYaw(User\CameraPivot)-360)*1.5)/2
Else
NYawAverage# = ((EntityYaw(User\ObjectNum)*.5)+(360-EntityYaw(User\CameraPivot))*1.5)/2
EndIf
;Run a check to see if these negative alternate values are more reasonable
If Abs(PitchAverage#-EntityPitch(User\ObjectNum)) > 180 Then PitchAverage# = NPitchAverage#
If Abs(YawAverage#-EntityYaw(User\ObjectNum)) > 180 Then YawAverage# = NYawAverage#
RotateEntity User\ObjectNum, XAng#, YAng#, 0
RotateEntity User\CameraPivot, WrapAngle(PitchAverage#), WrapAngle(YawAverage#), 0
If KeyDown(2) Then DebugLog "YAng: "+YAng#+" YawAvg: "+YawAverage#
;Set the rotation vector to the current orientation
User\Rotation = AngToVect(WrapAngle(YAng#-90), XAng#, User\Rotation)


Sledge(Posted 2004) [#2]

If anyone knows of a good way to have the camera follow behind an object with some speed lag then be my guest.



Fix a pivot behind your player and have the camera follow that while looking at the player (camera could have its own pivot which continually points at the trail pivot). If your camera cannot "see" the player then jump it to the trail pivot because it means it may have got snagged on something (I take it you don't want it floating through walls).

That would be my thinking.


Black Hydra(Posted 2004) [#3]
That isn't really my problem. I have a method that provides the camera to lock onto the player.

I also have a method that allows me to have some speed lag so that it isn't constantly locked to the player.

My problem is that when the object hits these odd angle values like 359 and 2 it finds the new camera angle to be something like 256. I have tried getting the negatives of the angles and using them as a method to get the true angle average, but it isn't working.

So if you have some code examples, or perhaps know of a method to get averaging of a circular number set (i.e. angles) that would solve my problem.

Thanks anyways, though.