code is in attachment. somehow it doesn't want to move in any way after pressing keys (i mean movement on plane, not camera view rotation which works very fine). actual output of file here for testing: http://hacknorris.myremotecentral.com/site_new any ideas to fix that? also - i want houses to be selectable (aka - clickable and then to show some iframe in 3d - saw tutorial of it too but just in case saying)
#(newbie) making site 3d. control problems
1 messages · Page 1 of 1 (latest)
what is even controls.object ?
idk, copied from examples on site…
hm , first person camera thing, I see...have you checked if properties actually change?
no?
you can go through simple process of looking at controls.object.position - see if it changes with key presses, if it doesn't - go step before that, to directions or input values
no
checked and always "unavailable"
maybe that's case on putting everything in init() , idk
checking my variable also doesn't work…
look at your keydown and keyup events
keydown - when you are pushing button down, keyup - when you release it.
simplified bug to this and still:
first version was better, you need both events
you just need to fix them
keydown - when you are pushing button down, keyup - when you release it.```
There's your hint, tha'll make ``controls.object.position`` change if you will set move variables correctly inside of key up\down events properly
now did something with a toggle but i don't think it was a good idea, now it's ice and doesn't stop runnin
do you set it to false on keyup?
document.addEventListener( 'keydown', function ( event ) {
switch ( event.code ) {
case 'ArrowUp':
case 'KeyW':
moveForward = true;
break;
case 'ArrowLeft':
case 'KeyA':
moveLeft = true;
break;
case 'ArrowDown':
case 'KeyS':
moveBackward = true;
break;
case 'ArrowRight':
case 'KeyD':
moveRight = true;
break;
}
});
document.addEventListener( 'keyup', function ( event ) {
switch ( event.code ) {
case 'ArrowUp':
case 'KeyW':
moveForward = false;
break;
case 'ArrowLeft':
case 'KeyA':
moveLeft = false;
break;
case 'ArrowDown':
case 'KeyS':
moveBackward = false;
break;
case 'ArrowRight':
case 'KeyD':
moveRight = false;
break;
}
});
no and for a while i was even toggling that lol
okay, so now other problem, how to make user not enter noclip home?
i mean, this in a tree for example:
you mean collide with objects? You'd need collision detection for it, idk if three.js on it's own has something for it, you'll probably need to ask someone else for it, I was using physX physics engine for collision detection \ response + physics, I think there should be something easier to implement with three if you only need collisions.
yea, that's called collision detection + collision response
@lunar lagoon , this guy should know what's usually used with three for simple collisions
I guess you could go really simple \ without any additional libraries and use raycast in a direction where you are moving to detect if there's something along the way and prevent going inside
that's what guy from example was using but he was creating cubes and i have .glb…
another option but a bit more complex to implement: https://gkjohnson.github.io/three-mesh-bvh/example/bundle/characterMovement.html
cool game
it doesn't really matter mesh or 3d model what you are using - you have direction vector where you are trying to move, that means you can cast a ray to that direction from your position and see if there's something along that vector, so for example - you are trying to move (0.5, 0, 0.5) - you cast a ray - detect a tree - find a distance - cut that vector short to prevent going inside that three.
this example i mean: https://threejs.org/examples/?q=pointer#misc_controls_pointerlock
there is something about raycast inside (but can go into a box)
didn't read through code much, but usually you have some kind of movement vector - direction*speed or same idea with velocity and acceleration and what not...
So that's the vector that should be responsible for movement + raycast + cut that vector short if collision detected
(bad at maths moment lol)
Check out this one: https://threejs.org/examples/?q=fps#games_fps
It uses an octtree... It's not as efficient as bvh, but it has a nice character controller feel.
you have velocity, so that is something, althrough with that code structure I'm really struggling to understand how it works
doing good a feeling 3d character controller from scratch is Hard, even for experienced devs. I highly suggest trying to adapt the bvh-character controller to your needs. It's a perfect fit for static environments, and also lets you do really tricky collision like shapecasts.