If you’re in the prototyping stage for your game, I’d suggest sticking to one kind of input until you have nailed down exactly what features you want and how you want to move the character.
That being said, the usual way to do this is to seperate the concept of moving around away from the concept of taking input.
Essentially you want your PlayerController to have something like a Move method. Then, you have another script that decides what kind of input to use and sends that input on to the PlayerController’s Move.
So it’d look something along the lines of:
public class InputController : MonoBehaviour {
public PlayerController player; //assign this in the inspector, or from a script
void Update() {
Vector3 movement;
if( //should use leopard input) {
movement = //Read input from leopard
}
else if(//should follow mouse) {
movement = //read input from mouse
}
else { //ie. should follow touch drag
movement = //read input from touch drag
}
player.Move(movement);
}
}
The idea here is to seperate concerns. Your player controller doesn’t need to know about input to move the character, it only needs to know in what direction it should move. This will make debugging a lot easier; if your character isn’t moving right, you can first check if it’s getting the correct input to it’s Move method. If the input is correct, then the bug is in the character controller. Otherwise it’s in the input controller.
This will also make it a lot easier to implement swiping and mouse movement - the problem isn’t “how to I make my character follow the mouse”, but “how do I send the direction from the character to the mouse as input to the Move method”, which is a much smaller problem.
Thank you!!! This helps a lot, and is how I suspected it might work. Just couldn’t find what you put so simply.
For what I have in mind, there will be some challenges: For keyboard/joystick, it’s just the direction of movement. For mouse hover/touch drag, it’s having the player under the input.
Also, the full scene is not in view. So when the mouse hover or touch drag reaches the edges, it will have to continue panning a bit.
But it’s already fun flying around the scene I made with the keyboard, so this will help me get the others going.