Redirecting input when mounting

I’m really new to Unity and am having difficulty finding any code examples that would show how to redirect input to another object(ex. turret) instead of the player after making him a child of the turret.

Thanks for any help pointing me in the right direction.
John

Hello!

you could create a script for your “turret” that receives input

hope it helps :wink:

I guess my question is how to redirect the mouse movements so that only the turret would receive the movements and not the player object. Would I need to create a global variable that says that the player is now attached and to ignore the movements or is there a better mechanism to handle this?

Thanks!

The idea of creating a global variable is a good solution :).

You could have an InputManager script that all other objects use to get their input. That script could then direct the flow of input. It’s a little more work, but if you need that level of control it’s worth doing.

So inside the input manager you could have a set of variables related to the turret movement, and then another set of variables related to the player input. Then in your update loop where you poll for input updates from the engine, you assign the variables based on what requires input at that time, and set the others to no input. That way the other scripts don’t even need to be told not to do anything, they just grab the input designated to them.

Thanks Murcho,

Sounds like a good solution to the problem and I will go with that approach since I was hoping to extend the code to also have the player drive vehicles and other game objects and my original idea would get messy.

I believe that I have gone through all the tutorials available with Unity and have not seen where the player can jump in a vehicle, drive, and then dismount. Has anyone created an example something like this by chance? If not it sure would be a nice addition :slight_smile:

John

It might be worth asking for a tutorial like that on the Wish List, JohnT - some of the wishes really do come true… :wink:

Thanks, done!