• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Stick camera to a unit

Status
Not open for further replies.
Level 2
Joined
Sep 9, 2005
Messages
26
Trying to make a camera stick to a unit and also follow its facing. My trigg looks like :
  • Camera Forwoard
    • Events
      • Player - Player 1 (Red) types a chat message containing cf as An exact match
    • Conditions
    • Actions
      • Camera - Apply Ground View <gen> for Player 1 (Red) over 0.00 seconds
      • Camera - Lock camera target for Player 1 (Red) to Chicken 0002 <gen>, offset by (0.00, 0.00) using The unit's rotation
Still this doesnt work it doesnt follow the units rotation
 
Level 2
Joined
Sep 9, 2005
Messages
26
That my friend is exactly what i am looking for.Problem is i have no ideea how to jass

  • globals
    • boolean array STPC_Blizzard_ActivateCamera
    • boolean array STPC_Blizzard_UseCustomValues
    • // Default
    • real STPC_Blizzard_CAMERA_FIELD_TARGET_DISTANCE = 700.
    • real STPC_Blizzard_CAMERA_FIELD_FIELD_OF_VIEW = 100.
    • real STPC_Blizzard_CAMERA_FIELD_ROTATION_VELOCITY = 1.3 // 1. = 100 %, .01 = 1 %
    • real STPC_Blizzard_CAMERA_FIELD_ZOFFSET = 100.
    • real STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK = 340.
    • real STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE = 300.
    • real STPC_Blizzard_CAMERA_FIELD_FARZ = 5500.
    • // Local player
    • real array STPC_Blizzard_CameraFieldTargetDistance
    • real array STPC_Blizzard_CameraFieldFieldOfView
    • real array STPC_Blizzard_CameraFieldRotationVelocity
    • real array STPC_Blizzard_CameraFieldZOffSet
    • real array STPC_Blizzard_CameraFieldAngleOfAttack
    • real array STPC_Blizzard_CameraFieldAngleOfAttackAlternative
    • real array STPC_Blizzard_CameraFieldFarZ
    • unit array STPC_Blizzard_CameraTarget
    • integer STPC_Blizzard_InstanceCounter = 0
    • real STPC_Blizzard_CameraTimerTimeout = .05 // 1. = 1 second
    • timer STPC_Blizzard_CameraTimer = CreateTimer()
    • trigger STPC_Blizzard_PanCameraTrig = CreateTrigger()
  • endglobals
  • function STPC_Blizzard_SetCameraCustomValues takes player whichPlayer, real cameraTargetDistance, real cameraFieldOfView, real cameraRotationVelocity, real cameraZOffSet, real cameraAoA, real cameraFarZ, boolean applySettings returns nothing
    • local integer playerIndex = GetPlayerId(whichPlayer)
    • set STPC_Blizzard_CameraFieldTargetDistance[playerIndex] = cameraTargetDistance
    • set STPC_Blizzard_CameraFieldFieldOfView[playerIndex] = cameraFieldOfView
    • set STPC_Blizzard_CameraFieldRotationVelocity[playerIndex] = cameraRotationVelocity
    • set STPC_Blizzard_CameraFieldZOffSet[playerIndex] = cameraZOffSet
    • set STPC_Blizzard_CameraFieldAngleOfAttack[playerIndex] = cameraAoA
    • set STPC_Blizzard_CameraFieldAngleOfAttackAlternative[playerIndex] = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE
    • set STPC_Blizzard_CameraFieldFarZ[playerIndex] = cameraFarZ
    • set STPC_Blizzard_UseCustomValues[playerIndex] = applySettings
  • endfunction
  • library STPCBlizzardApplyCustomCameraToUnit
  • function STPC_Blizzard_ApplyCustomCameraToUnit takes unit whichUnit, player whichPlayer, boolean turnCameraOn returns nothing
    • local integer playerIndex = GetPlayerId(whichPlayer)
    • set STPC_Blizzard_ActivateCamera[playerIndex] = turnCameraOn
    • if (turnCameraOn) then
      • set STPC_Blizzard_CameraTarget[playerIndex] = whichUnit
      • if (STPC_Blizzard_InstanceCounter == 0) then
        • set STPC_Blizzard_InstanceCounter = STPC_Blizzard_InstanceCounter + 1
        • call TimerStart(STPC_Blizzard_CameraTimer,STPC_Blizzard_CameraTimerTimeout,true,null)
      • else
        • set STPC_Blizzard_InstanceCounter = STPC_Blizzard_InstanceCounter + 1
      • endif
    • else
      • set STPC_Blizzard_InstanceCounter = STPC_Blizzard_InstanceCounter - 1
      • if (GetLocalPlayer() == Player(playerIndex)) then
        • call ResetToGameCamera(1.)
      • endif
      • if (STPC_Blizzard_InstanceCounter <= 0) then
        • set STPC_Blizzard_InstanceCounter = 0
        • call PauseTimer(STPC_Blizzard_CameraTimer)
      • endif
    • endif
  • endfunction
  • endlibrary
  • library STPCBlizzardCustomCamera requires STPCBlizzardApplyCustomCameraToUnit
  • function STPC_Blizzard_ResetCameraTarget takes nothing returns boolean
    • local integer playerIndex = 0
    • local unit cameraTarget
    • local location cameraSourceLoc
    • local real cameraSourceZ
    • local real cameraFieldTargetDistance
    • local real cameraFieldFieldOfView
    • local real cameraFieldRotationVelocity
    • local real cameraFieldRotation
    • local real cameraFieldZOffSet
    • local real cameraFieldAngleOfAttack
    • local real cameraFieldAngleOfAttackAlternative
    • local real cameraFieldFarZ
    • local real cameraTimerTimeout = STPC_Blizzard_CameraTimerTimeout * 2.
    • local real cameraRotationTime
    • loop
      • exitwhen playerIndex > 11
        • if (STPC_Blizzard_ActivateCamera[playerIndex]) and (STPC_Blizzard_CameraTarget[playerIndex] != null) then
          • set cameraTarget = STPC_Blizzard_CameraTarget[playerIndex]
          • if (GetLocalPlayer() == Player(playerIndex)) then
            • set cameraSourceLoc = GetCameraEyePositionLoc()
          • endif
          • set cameraSourceZ = GetLocationZ(cameraSourceLoc)
          • call RemoveLocation(cameraSourceLoc)
          • set cameraSourceLoc = null
          • if (STPC_Blizzard_UseCustomValues[playerIndex]) then
            • set cameraFieldTargetDistance = STPC_Blizzard_CameraFieldTargetDistance[playerIndex]
            • set cameraFieldFieldOfView = STPC_Blizzard_CameraFieldFieldOfView[playerIndex]
            • set cameraFieldRotation = GetUnitFacing(STPC_Blizzard_CameraTarget[playerIndex])
            • set cameraFieldRotationVelocity = ( GetUnitTurnSpeed(STPC_Blizzard_CameraTarget[playerIndex]) * STPC_Blizzard_CameraFieldRotationVelocity[playerIndex])
            • set cameraFieldZOffSet = (STPC_Blizzard_CameraFieldZOffSet[playerIndex] + GetUnitFlyHeight(STPC_Blizzard_CameraTarget[playerIndex]) + cameraSourceZ)
            • set cameraFieldAngleOfAttack = STPC_Blizzard_CameraFieldAngleOfAttack[playerIndex]
            • set cameraFieldAngleOfAttackAlternative = STPC_Blizzard_CameraFieldAngleOfAttackAlternative[playerIndex]
            • set cameraFieldFarZ = STPC_Blizzard_CameraFieldFarZ[playerIndex]
          • else
            • set cameraFieldTargetDistance = STPC_Blizzard_CAMERA_FIELD_TARGET_DISTANCE
            • set cameraFieldFieldOfView = STPC_Blizzard_CAMERA_FIELD_FIELD_OF_VIEW
            • set cameraFieldRotation = GetUnitFacing(STPC_Blizzard_CameraTarget[playerIndex])
            • set cameraFieldRotationVelocity = (GetUnitTurnSpeed(STPC_Blizzard_CameraTarget[playerIndex]) * STPC_Blizzard_CAMERA_FIELD_ROTATION_VELOCITY)
            • set cameraFieldZOffSet = (STPC_Blizzard_CAMERA_FIELD_ZOFFSET + GetUnitFlyHeight(STPC_Blizzard_CameraTarget[playerIndex]) + cameraSourceZ)
            • set cameraFieldAngleOfAttack = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK
            • set cameraFieldAngleOfAttackAlternative = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE
            • set cameraFieldFarZ = STPC_Blizzard_CAMERA_FIELD_FARZ
          • endif
          • if (GetLocalPlayer() == Player(playerIndex)) then
            • call SetCameraTargetController(cameraTarget, 0., 0., true)
            • if ( GetCameraField(CAMERA_FIELD_TARGET_DISTANCE) != cameraFieldTargetDistance ) then
              • call SetCameraField( CAMERA_FIELD_TARGET_DISTANCE, cameraFieldTargetDistance, cameraTimerTimeout )
            • endif
            • if ( GetCameraField(CAMERA_FIELD_FIELD_OF_VIEW) != cameraFieldFieldOfView ) then
              • call SetCameraField( CAMERA_FIELD_FIELD_OF_VIEW, cameraFieldFieldOfView, cameraTimerTimeout )
            • endif
            • if ( GetCameraField(CAMERA_FIELD_ROTATION) != cameraFieldRotation ) then
              • call SetCameraField( CAMERA_FIELD_ROTATION, cameraFieldRotation, cameraFieldRotationVelocity )
            • endif
            • if ( GetCameraField(CAMERA_FIELD_ZOFFSET) != cameraFieldZOffSet ) then
              • call SetCameraField( CAMERA_FIELD_ZOFFSET, cameraFieldZOffSet, cameraTimerTimeout )
            • endif
            • if ( GetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK) != cameraFieldAngleOfAttack ) then
              • call SetCameraField( CAMERA_FIELD_ANGLE_OF_ATTACK, cameraFieldAngleOfAttack, cameraTimerTimeout )
            • endif
            • if ( GetCameraField(CAMERA_FIELD_FARZ) != cameraFieldFarZ ) then
              • call SetCameraField( CAMERA_FIELD_FARZ, cameraFieldFarZ, cameraTimerTimeout )
            • endif
          • endif
        • endif
      • set playerIndex = playerIndex + 1
    • endloop
    • return false
  • endfunction
  • endlibrary
  • //===========================================================================
  • function InitTrig_STPC_Blizzard_Custom_Camera_View takes nothing returns nothing
    • local integer arrayIndex = 0
    • loop
      • exitwhen arrayIndex > 11
        • // Local player
        • set STPC_Blizzard_CameraFieldTargetDistance[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_TARGET_DISTANCE
        • set STPC_Blizzard_CameraFieldFieldOfView[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_FIELD_OF_VIEW
        • set STPC_Blizzard_CameraFieldRotationVelocity[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ROTATION_VELOCITY
        • set STPC_Blizzard_CameraFieldZOffSet[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ZOFFSET
        • set STPC_Blizzard_CameraFieldAngleOfAttack[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK
        • set STPC_Blizzard_CameraFieldAngleOfAttackAlternative[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_ANGLE_OF_ATTACK_ALTERNATIVE
        • set STPC_Blizzard_CameraFieldFarZ[arrayIndex] = STPC_Blizzard_CAMERA_FIELD_FARZ
        • set STPC_Blizzard_ActivateCamera[arrayIndex] = false
        • set STPC_Blizzard_UseCustomValues[arrayIndex] = false
        • set STPC_Blizzard_CameraTarget[arrayIndex] = null
      • set arrayIndex = arrayIndex + 1
    • endloop
    • call TriggerRegisterTimerExpireEvent( STPC_Blizzard_PanCameraTrig, STPC_Blizzard_CameraTimer )
    • call TriggerAddCondition( STPC_Blizzard_PanCameraTrig, Condition (function STPC_Blizzard_ResetCameraTarget))
  • endfunction[/triggger]
    • this is the trigg in the map can someone tell me how i can copy this to mine and what im missing ?
  • The point is i need it to work like this when i send a text msg it should pan to 1 of 4 units depending on the msg. And i will need a trigg to simply disable it...
 
Level 3
Joined
Jun 6, 2008
Messages
51
in case you haven't figured it out and none else has answered somewhere else(after 4 months :hohum:)
  • Camera Forwoard
    • Events
      • Player - Player 1 (Red) types a chat message containing cf as An exact match
    • Conditions
    • Actions
      • Camera - Apply Ground View <gen> for Player 1 (Red) over 0.00 seconds
      • Camera - Lock camera target for Player 1 (Red) to Chicken 0002 <gen>, offset by (0.00, 0.00) using The unit's rotation
      • Camera - Set Player 1 (Red)'s camera Rotation to (Facing of Chicken 0002) over 0.00 seconds
Unfortunately, it doesn't lock the Camera's rotation to the unit (which I think you are trying to do), So you will have to do

  • Camera Forwoard
    • Events
      • Player - Player 1 (Red) types a chat message containing cf as An exact match
    • Conditions
    • Actions
      • Camera - Apply Ground View <gen> for Player 1 (Red) over 0.00 seconds
      • Camera - Lock camera target for Player 1 (Red) to Chicken 0002 <gen>, offset by (0.00, 0.00) using The unit's rotation
      • Camera - Set Player 1 (Red)'s camera Rotation to (Facing of Chicken 0002) over 0.00 seconds
      • Set CameraForwoardActive = True
  • Camera Forwoard lock
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
      • CameraForwoardActive Equal to True
    • Actions
      • Camera - Set Player 1 (Red)'s camera Rotation to (Facing of Chicken 0002) over 0.00 seconds
And when you want it to stop doing this, put in some other trigger that changes CameraForwoardActive to false and resets the players camera.

omg thread necromancy! :witch_doc_sad:
 
Status
Not open for further replies.
Top