How do i move the player to the top of a horse?

In Grand Theft Auto, when you stand close to a car you can press a button and the guy gets in the car. In Halo when you stand next to a vehicle you press a button and you get in! i want to know how to move the player from wherever he is around the horse to beside it, (plays a climbing up animation) then on top… it seems like it would be easy for someone who knew python :o

Yes, Python will be needed, especially for positioning the Player to the given point and orienting it into the right direction. The way I’ve done this before is like this:

  • parent an Empty to the Horse at the position where the Player will rest, name it ‘Saddle’
  • parent a Cube to the Horse and scale the mesh so it sticks out of the right and left side of the horse where the Player has to mount, give it Sensor Physics, name it ‘Irons’
  • add a Keyboard Sensor and Collision Sensor to the Box, with Property ‘player’ (give the Player this Property too)
  • attach the Sensors to a Python Controller, Type Module
  • name the script ‘Horse.py’ and name the Controller ‘Horse.mount’
  • paste the following:
def mount(cont):
    keyboard_sensor, collision_sensor = cont.sensors
    if keyboard_sensor.positive and collision_sensor.positive:
        saddle = cont.owner.parent.children['Saddle']
        player = collision_sensor.hitObject
        player.setParent(saddle, False, True)
        player.worldTransform = saddle.worldTransform

For more information about the attributes that are used in the script, search the API.

Of course this script is just an example. Things have to be added (or changed) if you want to be able to jump off of the horse again.

this can be a sort of GTA prototype :eek:

press WSAD to move and space to jump in/out of the car (or change car!:cool:)

state available : walk / drive :wink:

Attachments

GTA_ALPHA.blend (262 KB)

thanks, both of you. I tried Raco’s solution first but all that happened was the player was parented to the horse and when it turned the player was sent flying… then i took a look at the gta demo, and it looked very promising, so I’l try to implement that in the game!

if your player has physics and the horse too, you need to disable physics for the player when you put it on the horse and turn it back on when you dismount. the relevant functions are bge.types.KX_GameObject.suspendDynamics and bge.types.KX_GameObject.restoreDynamics otherwise since player and horse most likely intersect, they trigger a collision and get pushed away from each other

well, of course use it as you want :wink:

the script anyway is a bit too “centralized” work well just for a little demo , if you have different “car” or horse , maybe is better move the logic more explicitely on the car/horse, in this way also NPC can use it …just a guess

I don’t understand. Then you may have overlooked something. Here’s the blend:

Attachments

HorseMount_00.blend (91.5 KB)

Hmm… I did pretty much the same thing, but yours works and mine didn’t. :eyebrowlift2: I didn’t save it so I cant look back and see what I did wrong. But that is specifically just what i needed. now to make him get off the horse…

Well a player move fast to horse. this time player fast.

That’s quite easy. Since mounting a horse is traditionally on the left side you could position the irons there and use this position to restore the player position. The player Physics were set to Ghost while parenting to the horse, so Ghost must be disabled while dismounting. Momentarily the only way to do this is to parent it to some object, and then remove that parent. It’s a workaround, but if it works, it works. It’s just one line more.

I don’t know what you mean.

Attachments

HorseMount_01.blend (92.4 KB)

Problem solved.