switsching active player

i know this question was asked in sort of the same way before, but i cant find the right thread anymore.

I got my character and i want him to be deactivated if he gets in/on a vehicle. My example in my current game is: My player should be able to ride a horse. So i got two characters. My player and the horse. How do i set up the logic bricks or a script, so that the player doesnt move anymore when he sits on the horses back? Maybe with a NEAR property?

But more complicated: How do i tell the horse to only move with the arrow keys on my keaboard, if the player sits on its back? a NEAR property wouldnt work here, because it would be activated if the player stands at the horses side, too.

Im sorry if this question was asked before, yust give me the link if it answeres my question, please.

Thanks a lot :smiley:

Are you using python for this project or just logic bricks?

You can use a property that tell the actor if he is active or not. Do it on the player and the horse.

If the property is true (or 1 if integer) then the controls should be enabled. You can do this by adding an property sensor that checks for the correct value. connect this sensor with the “AND” controllers of your controls.

player objects:

property "active" as int default = 1 (or 0)

property sensor  --> AND controller --> controls Actuator
active = 1        ->
                /
controls sensor/
...

Do this for every controller you want to enable/disable.

Add the same logic to your other actors (e.g horse).

Make sure only one actor has the property set to 1. All other should be set to 0. Otherwise you would control two actors at the same time (nice feature :slight_smile: ).

To switch between the actors you need to

a) change the property of the new actor to 1 and
b) change the property of the active actor to 0

There are many ways to achieve this. Here an example:

a) Connect a sensor from any object to a message actuator sending an enable message to the new actor. Don’t forget the “OB” at the beginning of the to field (e.g. “to: OBCube”). The subject could be “enable”.

b) connect another message actuator to the same controller sending an “disable” to everyone (means leave the to: field empty).

any object:

any sensor ---> AND controller ---> message actuator to OBHorse
                                    with subject "enable"
                                 -> message actuator  
                                    with subject "disable"

now you need a message sensor to react on enable and one to react on disable messages:

player objects:

message sensor ---> AND controller ---> property actuator 
subject: disable                        active = 0

message sensor ---> AND controller ---> property actuator 
subject: enable                         active = 1

what happens:
if the “any” sensor is triggered ( remember it does not need to be an actor )

  1. a disable message is send to every object
  2. an enable message is send to the new active object (horse)
  3. all actor objects (player and horse) receive the disable message and set active to 0 (use debug button on the properties)
    3a. The controls do not work anymore on the actors.
  4. the new active object (horse) gets the enable message and sets property to 1
    4.a. the active object can use the controls.

to switch back you need a different sensor to send the enable message to the player (and the disable messages to everyone else (horse))

Alternatively you can send disable massages directly to the actor that should be deactivated (player). But this increases the amount of message actuators with the amount of actors.

( Sensors should be without any pulse mode)

Hopefully this helps.