Antares
Spell Reviewer
- Joined
- Dec 13, 2009
- Messages
- 983
Hello there,
I'm trying to make a camera system in which the camera is locked to the player's hero by default, but once the player is attempting to scroll the camera (or clicks on the minimap), the camera unlocks until he or she locks it again.
I tried to implement the camera lock with SetCameraPosition on a 0.02s loop, then check each time if the camera position is not where it should be to see if the player wants to move the camera. The code is asynchronous.
The problem I'm running into is that there seems to be a delay with GetCameraTargetPositionX() and the camera displacement is never registered. I think the camera is returned back to the original place with SetCameraPosition before it returns the value. Sometimes, you can scroll just fine, sometimes it takes 1-2 seconds before it moves, sometimes it remains locked permanently. I'm guessing that's based on how the internal camera update lines up with my loop.
Is there a way to fix this or maybe a completely different, better method to achieve the same goal?
Thanks!
I'm trying to make a camera system in which the camera is locked to the player's hero by default, but once the player is attempting to scroll the camera (or clicks on the minimap), the camera unlocks until he or she locks it again.
I tried to implement the camera lock with SetCameraPosition on a 0.02s loop, then check each time if the camera position is not where it should be to see if the player wants to move the camera. The code is asynchronous.
JASS:
//only runs for Player P.
if lockCamera[P] then
set dx = cameraX[P] - GetCameraTargetPositionX()
set dy = cameraY[P] - GetCameraTargetPositionY()
if dx > CAMERA_UNLOCK_MIN_DIST or dx < -CAMERA_UNLOCK_MIN_DIST or dy > CAMERA_UNLOCK_MIN_DIST or dy < -CAMERA_UNLOCK_MIN_DIST then //CAMERA_UNLOCK_MIN_DIST = 10
set lockCamera[P] = false
else
set cameraX[P] = x
set cameraY[P] = y
call SetCameraPosition( cameraX[P] , cameraY[P] )
endif
endif
The problem I'm running into is that there seems to be a delay with GetCameraTargetPositionX() and the camera displacement is never registered. I think the camera is returned back to the original place with SetCameraPosition before it returns the value. Sometimes, you can scroll just fine, sometimes it takes 1-2 seconds before it moves, sometimes it remains locked permanently. I'm guessing that's based on how the internal camera update lines up with my loop.
Is there a way to fix this or maybe a completely different, better method to achieve the same goal?
Thanks!