Hi I’m new here. I was making a game where I have the requirement to get in the car and get out. While I am able to get in but I cannot get my character to get out
Here is my code:
if(collision!=true){
// here it adds the wasd input to the player velocity when the player is not in the car
impostor.setLinearVelocity(new BABYLON.Vector3(x, velocity3d.y, z))
}
else if(isPressed("f")&& collision==true) {
// when the player collides with the tigger box and the user presses "f" , camera changes to camera1 giving the effect of him getting in the car , I also remove the player mesh and he cant move the player as it is only when collision!=true ( first condtion)
scene.activeCamera=camera1;
mesh.isVisible=false;
collision=false;
incar=true;
console.log("in car now")
}else if(scene.activeCamera==camera1){
//but when the player is already in the car, the scene.aciveCamera is camera1 so I can just use that with isPressed(key:string) that is "f" and i change back the activeCamera to camera :D , if only if would work
console.log("getting out of car")
scene.activeCamera=camera;
mesh.isVisible=true
impostor.setLinearVelocity(new BABYLON.Vector3(x, velocity3d.y, z))
incar=false;
}
})
Repro - is short from REPRODUCE.
It means to reproduce (repeat) your problem in Playground so everybody could help you without guessing about what your code is.
But, I think you’re missing the point I started the thread for. ( switch camera on keypress)
but yeah the rotate mesh thing isn’t working on my local thing ( and its vastly different from the one in the playground)
as it is taking too long for me to re create the thing in PG , I will be linking a video and code files ( on request/ if you want) so that you understand the problem better
the file upload limit is only 4MB
so i only could upload this much
also, you can check out our website https://benevolent.games/
you’ll get the gist of what I’m talking about.
but fortunately this is enough to explain
I need to change the camera like I did here but back to the original
which is not happening
and also I need help making the car move but that’s for later ( I have seen almost every post you’ve and @raggar has posted)
Not having a Playground reproduction makes it much harder for the community to be able to take a look at your problem, so I recommend having a PG if you’d still like help. It doesn’t need to be your entire game and use your assets, the simplest the better.
All I can see from this small part of code is that it’s based on collision and is also not returning a value for ‘incar’.
Are you sure ‘incar’ is actually set for your second part of script and/or collision is not blocking the script? No offense, I’m just asking, since this has been going on for a while. Sometimes the answer is just so simple that you cannot see it anymore.
well, you have two parameters in there that will decide on whether the function will trigger or not:
The collision and the ‘incar’ var. I believe first would be try determine if either of these is blocking and in case, which one is.
It is possible that the var ‘incar’ is not updated at the very time you interact again with the collision box. It’s also possible that the collision box (in or out) is not detected at the very time you call the ‘incar’ var.
For debug, I guess I would want to remove one of these triggers and check it. Next, remove the other and check it. Once I’m sure they all work independantly, reinstate both and if still buggy, I would know that the issue is with the order/combination of both.
Edit: May be add something like this
(impostor)…onCollideEvent = function(collided) {return incar;}