Entering a vehicle

I want to be able to step into a vehicle and to drive with it, but my code isn’t working

this is my code:[java]//import some stuff

private PhysicsVehicleNode vehicle;

private PhysicsCharacterNode player;

private int Vehicle = 0;

public class Main extends SimpleApplication implements ActionListener{

public void SimpleInitApp(){

inputManager.addMapping(“Enter”, new MouseButtonTrigger(KeyInput.KEY_RETURN));

inputManager.addListener(this, “Enter”);

//some other stuff that doesn’t matter in this topic

public void onAction(String binding,boolean keyPressed,float tpf){

if (binding.equals(“Enter”)){

if (Vehicle == 0 && this.CalculateDistance(player.getLocalTranslation(),vehicle.getLocalTranslation()) <= 100){

Vehicle = 1;

} else if (vehicle != 0){

Vehicle = 0;

}

}

//some other keys

}

public void SimpleUpdate(float tpf){

//some navigation actions

if (Vehicle == 1){

player.setLocalTranslation(vehicle.getLocalTranslation());

}

player.setWalkDirection(walkDirection);

cam.setLocation(player.getLocalTranslation());

}

public float CalculateDistance(Vector3f point1,Vector3f point2){

return FastMath.sqr((point2.x - point1.x)(point2.x - point1.x) + (point2.y - point1.y)(point2.y - point1.y) + (point2.z - point1.z)*(point2.z - point1.z));

}[/java]When i pres return while standing next to the vehicle, nothing happens.

What am i doing wrong?

Are you sure you want to press enter button on your mouse ? :wink:



new MouseButtonTrigger(KeyInput.KEY_RETURN)



shouldn’t it be rather KeyTrigger(KeyInput.KEY_RETURN) ?

abies said:
Are you sure you want to press enter button on your mouse ? ;)

new MouseButtonTrigger(KeyInput.KEY_RETURN)

shouldn't it be rather KeyTrigger(KeyInput.KEY_RETURN) ?

that was a stupid mistake, but i changed it now and it still isn't working

Hi,



Just a guess, but isnt the Physics/Collision system preventing you from putting one object at the exact same position as another? You could possibly jump ontop of the car etc.



On entering the vehicle, it would be necessary for the player to “fit” inside the car somehow, like in the GTA games where you can climb into a car.



I would say you are going to have to first design a car model that can hold a player inside it. Then you would most likely “attach” the player to the car, so that when the car moves, the player moves with it.



Sorry for the lame explanation, but I am very new to 3D stuff.

Basic idea:



Destroy player physic and attach him to the car on entering

On exiting detach player and recreate the physic for it.

Depending on game you might want to put a ghostnode on the position the player is inside the car so he can be shoot or similar.





Measnwhile you could play a getting into car, exiting car animation.

jatheron said:
Hi,

Just a guess, but isnt the Physics/Collision system preventing you from putting one object at the exact same position as another? You could possibly jump ontop of the car etc.

On entering the vehicle, it would be necessary for the player to "fit" inside the car somehow, like in the GTA games where you can climb into a car.

I would say you are going to have to first design a car model that can hold a player inside it. Then you would most likely "attach" the player to the car, so that when the car moves, the player moves with it.

Sorry for the lame explanation, but I am very new to 3D stuff.

the physics system isn't preventing it. It just does weird stuff when 2 solid objects are attached to each other at the same location, so i now only attach the camera.

when i only check the keys, and not the distance, it works well. Does anybody knows a good way to calculate distance that works?

Physics is controls now exactly because of this. You have the character or rigidbody control while you move outside, then you disable/remove it, play an animation of the character getting in the car and then let the player control the car while the model is attached to it.

How do you set the direction of the camera in the direction of the car? i tried it, but then i saw only stripes, and when i took a screenshot of it, it looked normally. How can i let the camera point at the car withouth this effect?