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