What's wrong with this code?
Blitz3D Forums/Blitz3D Beginners Area/What's wrong with this code?
| ||
This code allows the camera to be rotated around some object. The object should then turn to point in the same direction as the camera via the shortest route. I've tweaked with the variables a lot; sometimes the object rotates in the wrong direction, sometimes it doesn't stop, sometimes it doesn't move at all. I think it has something to do with the fact that, by default, my object has yaw = 0 and my cameraPivot has yaw = 180 initially. This is needed for the correct orientation of the viewer initially. Can anyone find the problem? [Code] ; Ensure that the mouse never leaves the screen bounds. If ( MouseX() > 1200 ) Or ( MouseX() < 50 ) Or ( MouseY() > 1000 ) Or ( MouseY() < 50 ) Then MoveMouse 640, 512 EndIf ; Turn cameraPivot, thus making camera spin around it. TurnEntity cameraPivot, MouseYSpeed() / 1.5, -MouseXSpeed(), 0 ; Always keep cameraPivot's roll 0 wrt the horizontal plane. RotateEntity cameraPivot, EntityPitch(cameraPivot), EntityYaw(cameraPivot), 0 If EntityYaw(player\model) > 0 If EntityYaw(cameraPivot) < EntityYaw(player\model) TurnEntity player\model, 0, 1, 0 ElseIf EntityYaw(cameraPivot) > EntityYaw(player\model) TurnEntity player\model, 0, -1, 0 EndIf Else If EntityYaw(cameraPivot) < 360 + EntityYaw(player\model) TurnEntity player\model, 0, 1, 0 ElseIf EntityYaw(cameraPivot) > 360 + EntityYaw(player\model) TurnEntity player\model, 0, -1, 0 EndIf EndIf [/Code] |
| ||
Bear in mind that entityyaw() returns -180 to 180 not 0 - 360. Something like this should work .. turnentity player\model, 0, ( entityyaw( camerapivot, 1 ) - entityyaw( player\model ) ) * .1 ,0 or .... global Pivot = createpivot() ;reuse this tformpoint 0, 0, 10, camerapivot, 0 positionentity Pivot , tformedx(), tformedy(), tformedz() turnentity player\model, 0 , deltayaw( player\model, camerapivot ) * .1, 0 Stevie |
| ||
you mean, you want to something like this ? |