5
\$\begingroup\$

In the game i am creating as an hobby (learning is the primal goal of it all) i plan to implement a space ship that the player can enter and use to explore it. I tried to search the internet for the concept of vehicle implementation but i couldnt find anything worth mentioning, and before I start writing the code I really want a clear idea of what I strive for. So id like to ask the pro game developers how should I look at a vehicle, should I think of it as a player's body extention with different mechanics? or should I just think of it as a usable exterior object? What kind of link should be between the player and the drivable vehicle? How do games usually do it, like GTA 2 and that kind of games?

Main Question: What is the basis of vehicle implementation?

P.S. I dont think its important to mention but the game is 2D and top-down perspective, so i guess GTA 2 can be a close reference to what i wanna do, although the gameplay is very different, but ye, the vehicle implementation i want is similar to GTA 2 although i only plan to do a space ship for now.

\$\endgroup\$

1 Answer 1

4
\$\begingroup\$

Most likely you will have a variable stored somewhere that is the current object (depending on how everything is set up).

This variable will be a pointer for a bunch of things such as the camera's anchor but also control.

For example (not java, just pseudo):

// Start up
var main_dude:Entity = new Dude();
var controlled_character:Entity = main_dude;

// Listen to events 
this.addEventListener(ENTER_VEHICLE, onEnterVehicle);

// Later, as part of your main update cycle
function update() {
    controls.update(controlled_character); // listen for input, and update the controlled entity, what ever that is, if anything 
    camera.update(controlled_character); // make sure camera is still over the main character
}

// Later later, depending on how your events are set up
function onEnterVehicle(enteredVehicle:Entity) {
   controlled_character = enteredVehicle; // now during the above update loop, the controls are being applied to the car, not the person
   main_dude.visible = false;
}    
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .