How do you go about making a character switch mechanic?

(Camos1011) #1

I haven’t found any fleshed out tutorials on how to do this given that I’m a dumb newbie. I have the ai I need sorted out but, switching between characters or even objects I’m finding difficult. The subjects that do mention this only want it as a secondary thing.
Think RTS character cycling but, for a TPS.
Please help.

(Camos1011) #2

I was tinkering around with this mechanic and was trying to alter the button configuration to be wasd based instead of mouse based.
Would be nice to have some help.

character select mechanic save2.blend (362.2 KB)

(Cotaks) #3

What do you exactly want? just something to switch characters?

You can handle this in a few ways.

The easiest is to change the mesh into an other mesh. Or by adding the player, then remove it add a new object and keep using the new object.

Or are you looking for a working navmesh pathfinding?

anyway something to look at:
pathfinding with navmesh:

In your blend, target script needs the converting of mouse to keyboards, same thing with target , mouse click should be replaced with a keyboard sensor, so instead of clicking with the mouse you need to press a key.

(jesusmora) #4

switch character as in, you have two characters in two places and you want to move the camera and controls beetwen them? or as in, you have two character and you want to replace one for another?

it’s quite easy, you need a property in both characters (let’s call it “active”), when you press the switch button, the active character’s property becomes True, and the other False, and when you press it again it changes it.

if switch_button.positive:
    if char_1["active"] == True:
          char_1["active"] = False
          char_2["active"] = True
    elif char_2["active"] == True:
          char_1["active"] = True
          char_2["active"] = False

then you add a condition at the start of all the characters’s scripts checking for the property to be True to work:

if obj["active"] == True:
    #Movement/Action code

That way the character that is not active does not respond, and you can use obj.worldPosition to move it to a hidden room so it’s not seen, or change the camera, or you can add additional code instead of pass, if you want it to do something else like follow the other character.

(BluePrintRandom) #5

this does not have the camera control script in yet

just parent a empty or use a offset from a body part of the actor to place the camera like this

own.scene.active_camera.worldPosition = own.scene.active_camera.worldPostion.lerp( pos ,rate)
own.scene.active_camera.worldOrientation = own.scene.active_camera.worldOrientation.lerp( rot, rate)

pos and rot can be gathered from the controller object’s target or own of it’s child objects.

controller[‘Target’].childrenRecursive etc.

(BluePrintRandom) #6

there is a newer version in the BGMC 28 or 29 {can’t remember} star tribe

(Camos1011) #7

What I want is to have a script that allows the player to switch between characters but, the character (s) not in control at present will behave like a friendly NPC. Like Donkey Kong Country or like an RPG battle system but, independent allies for example.

(Camos1011) #8

You guys are all amazing and I shall check out all of your code. Thank you!

(Camos1011) #9

Alright I was wondering how to simply press a button cycle back and forth between two characters without an aiming system.
I tried making one here but, it’s really bad xD.
Character switch.blend (519.2 KB)

(Cotaks) #10

Something like this?
switch char controls.blend (474.1 KB)
Very simple logic bricks (w to move, left shift to switch)

(Camos1011) #11

I’ll bet it was so easy I’d look at it and face palm.
I’m kinda getting the hang of some of the python end by reverse engineering but, also getting the hang of logic bricks a bit.
There just isn’t much documentation on what I want to do.
Now that I requested the stuff there will be.