playMaker

Author Topic: Drag Camera Action does not work (RESOLVED)  (Read 424 times)

Aaddiction

  • PlayMaker2 Beta
  • Full Member
  • *
  • Posts: 174
Drag Camera Action does not work (RESOLVED)
« on: January 04, 2026, 06:17:32 AM »
Hello, it seems Drag Camera action does not work with me. Is there something specific I need to do other than the action itself?

« Last Edit: January 08, 2026, 02:02:28 PM by Aaddiction »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4307
  • Official Playmaker Support
    • LinkedIn
Re: Drag Camera Action does not work
« Reply #1 on: January 06, 2026, 09:52:31 PM »
I'm not familiar with that action (I don't think it's built in).  Is the legacy input manager enabled in the project? The action might use it. If you post the code I can take a look.

Aaddiction

  • PlayMaker2 Beta
  • Full Member
  • *
  • Posts: 174
Re: Drag Camera Action does not work (RESOLVED)
« Reply #2 on: January 07, 2026, 02:07:39 PM »
EDIT: I resolved it, it was a mistake on my side. You need to uncheck "use touch" option.

Here's the code, action is from Ecosystem. Both input systems are activated.
Thank you in advance!

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Camera)]
[Tooltip("Drag Camera with mouse or touch.")]
[HelpUrl("http://hutonggames.com/playmakerforum/index.php?topic=10163")]
    public class DragCamera : FsmStateAction
{

[ActionSection("Setup")]
[RequiredField]
[CheckForComponent(typeof(Camera))]
[Tooltip("The main camera (should have a Camera component).")]
[Title("Camera")]
public FsmGameObject cameraObj;

[Tooltip("Movement speed.")]
[RequiredField]
public FsmFloat speed;
[Tooltip("How smooth it should be. Highest number = Higher smoothness.")]
[RequiredField]
[TitleAttribute("Smoothness")]
public FsmInt smoothControl;

[ActionSection("Options")]
[Tooltip("Use touch and not mouse")]
public bool touchInput;
[Tooltip("Only use Z axis")]
[TitleAttribute("Z Axis Only")]
public bool zoomOnly;

[ActionSection("Mouse Input Options")]
[Tooltip("Use a key. None = Off")]
public KeyCode key;
public enum ClickVariable {Left, Right, Middle};
public ClickVariable mouseButton;

[ActionSection("")]
public FsmBool cameraMoving;
[Tooltip("Disable Action")]
public FsmBool disable;
[TitleAttribute("Disable and Finish Action")]
public FsmBool disableExit;

bool active;
Vector3 swipePos;
Vector3 dragPos;
int mouseInt;
private FsmBool storeResult;
bool useKey;

public override void Reset()
{
cameraObj = null;
speed = 1.2f;
smoothControl = 25;
active = false;
touchInput = true;
disable = false;
disableExit = false;
cameraMoving = false;
zoomOnly = false;
mouseInt= 0;
key = KeyCode.None;
storeResult = false;
}

public override void OnPreprocess()
{
#if PLAYMAKER_1_8_5_OR_NEWER
Fsm.HandleLateUpdate = true;
#endif
}

public override void OnEnter()
{

setKey();

switch (mouseButton) {
case ClickVariable.Left:
mouseInt = 0;
break;
case ClickVariable.Right:
mouseInt = 1;
break;
case ClickVariable.Middle:
mouseInt = 2;
break;
}

}

public override void OnLateUpdate()
{

if (useKey){

storeResult.Value = Input.GetKey(key);

}

if (!disable.Value & !disableExit.Value){

if (!touchInput) {
MouseControl();
}
else {
TouchControl();
}
}


if (disableExit.Value)
{
Finish();
}

}

void MouseControl()
{

if (useKey){

if (Input.GetMouseButtonDown (mouseInt) && active==false && storeResult.Value == true) {

swipePos = Input.mousePosition;
active = true;
cameraMoving.Value=false;
}

if (Input.GetMouseButtonUp (mouseInt) || storeResult.Value == false) {
active = false;
cameraMoving.Value=false;
dragPos = swipePos;
}

dragCameraAction();
}

if (!useKey){

if (Input.GetMouseButtonDown (mouseInt) && active==false) {

swipePos = Input.mousePosition;
active = true;
cameraMoving.Value=false;
}



if (Input.GetMouseButtonUp (mouseInt)) {
active = false;
dragPos = swipePos;
cameraMoving.Value=false;
}

dragCameraAction();

}

}


void TouchControl()
{

if (Input.touchCount > 0 && active==false) {

swipePos = Input.GetTouch(0).position;
active = true;
cameraMoving.Value=false;
}

if (Input.touchCount == 0) {
active = false;
dragPos = swipePos;
cameraMoving.Value=false;
}

dragCameraAction();
}

void dragCameraAction()
{

if (active== true && zoomOnly == false) {

if (touchInput) {

dragPos = Input.GetTouch(0).position;

}

else {

dragPos = Input.mousePosition;

}

if(swipePos.x < dragPos.x - Screen.width/smoothControl.Value){
cameraMoving.Value=true;
cameraObj.Value.transform.position -= new Vector3((dragPos.x - swipePos.x)/(Screen.width/speed.Value),0,0);
}

if(swipePos.x > dragPos.x + Screen.width/smoothControl.Value){
cameraMoving.Value=true;
cameraObj.Value.transform.position += new Vector3((swipePos.x - dragPos.x)/(Screen.width/speed.Value),0,0);
}

if(swipePos.y > dragPos.y + Screen.width/smoothControl.Value){
cameraMoving.Value=true;
cameraObj.Value.transform.position += new Vector3(0,(swipePos.y - dragPos.y)/(Screen.width/speed.Value),0);
}

if(swipePos.y < dragPos.y - Screen.width/smoothControl.Value){
cameraMoving.Value=true;
cameraObj.Value.transform.position -= new Vector3(0,(dragPos.y - swipePos.y)/(Screen.width/speed.Value),0);
}

}

else{

if(swipePos.y > dragPos.y + Screen.width/smoothControl.Value){
cameraMoving.Value=true;
cameraObj.Value.transform.position += new Vector3(0,0,(swipePos.y - dragPos.y)/(Screen.width/speed.Value));
}

if(swipePos.y < dragPos.y - Screen.width/smoothControl.Value){
cameraMoving.Value=true;
cameraObj.Value.transform.position -= new Vector3(0,0,(dragPos.y - swipePos.y)/(Screen.width/speed.Value));

}
}
}

void setKey()
{

useKey = true;

switch (key) {
case KeyCode.None:
useKey = false;
return;
}
return;
}




}
}
« Last Edit: January 07, 2026, 02:12:03 PM by Aaddiction »