0 Favourites

How do I Enter/Exit Vehicles (Solved)

  • I am trying to find the best way to exit and leave vehicles

    players walks up to vehicle do a check to see if player is with in 16 pixels of vehicle then player can press the "E" key to enter vehicle. when the player is done the player can press E to exit vehicle and the vehicle stays at the location is was driven too. and the player will spawn right next tot he vehicle.

    I got most of this done, the hard part I am having it pressing the E key to enter on 16 pixel radius check.

    I have it set to if player is on collusion then enter vehicle. with no Key press action.

  • Do you need a 16 pixel check? Why not just press E when overlapping the vehicle sprite?

    Anyway, what I would do in that situation is create an invisible sprite that is pinned to the vehicle which is the size of the area you want for entering the vehicle. Then E pressed, if overlapping the invisible sprite, enter vehicle.

    I'm sure there is a way to do it with expressions, so maybe someone else will bring up another solution.

  • Another way is to pin an invisible box to the character itself for all the intreraction triggering so you don't need to have it on everything. So when the box ovelapps the car, a door etc you can perform the interaction.

    And I think it it easier to just hide the character and align it with the cars front door and pin it there while driving and unhide it when exiting the vehicle. Then you don't have to destroy and spawn the character again and all of its assets and settings.

  • Thank you for the insight, I am still however having some issues using the keyboard command to enter my car.

    Right now I have it set to on collusion to enter the car. but I want to do 2 checks, is player next to car, is key E pressed. so far I am un able to run both checks

  • if you upload some simple capx..You'll quickly come to a solution..

  • You should make an event like this: When the E key is pressed and the triggerbox is colliding with the car as another condition --> then enter car or whatever setup you have.

    You don't want to make a check to see if the E key is pressed. The pressing of the E key is the trigger itself and tells C2 you are pressing that key.

  • as soon as I get off of work I will send a copy of my master peic.... err I mean my project

  • Here is the file,

  • the issue is when I set event to keyboard key pressed E I cannot add On collision with event in the same area ( guessing it is the AND logic)

  • I think you should be checking for overlaps not collisions

  • However you may have the same issue as me, which is that on entering the vehicle the exit conditions are immediately filled and the player 'exits' again.

    Sorry to bomb your thread btw, but as we're trying to do the same thing it seemed extraneous to create another.

    Anyway this is one example of how I was trying to do it, If I disable the exit portion of the script then the guy 'enters' the vehicle and I can control it. I've got no idea how to handle exiting the vehicle though!

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • This is one way to do it. Not the best example but you can clean it up a bit. Just wanted to show you guys the concept

    I choose to hide the player and not pin him to the car. I just move the player to the cars front door position when exiting the car.

    In a bigger game I would use functions instead so you don't have to do the same events over and over again with different cars.

    And just like ForgedByHand said. You can't add "on collision" as a condition to "on e pressed" because both are triggers. You have to check for "is overlapping" wich works as a condition for a trigger event.

  • this is what I have been looking for and the trigger was the key. (Like your art LOL)

    Now if you can help me figure out my trailer issue I can move forward with my game.

  • Glad it helped.

    I know my art is top notch, only took me a few hours to create the player and the car

    So what is the problem with the trailer?

  • here is the capx file with the trailer, what I am trying to do is set up a hook up between tractor image point "hitch" and trailer image point "hitch" and when i drive around, i want it to feel like a trailer:

    turning, pulling, backing up, and later i will add weight depending on how much is loaded in it, to get the pulling feeling. but right now I just need the hook up and trailer to turn with the tractor/ backing up,

Jump to:
Active Users
There are 2 visitors browsing this topic (0 users and 2 guests)