#(newbie) making site 3d. control problems

1 messages · Page 1 of 1 (latest)

muted bloom
#

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)

shut dust
#

what is even controls.object ?

muted bloom
#

idk, copied from examples on site…

shut dust
#

hm , first person camera thing, I see...have you checked if properties actually change?

muted bloom
#

no?

shut dust
#

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

muted bloom
#

no

#

checked and always "unavailable"

#

maybe that's case on putting everything in init() , idk

#

checking my variable also doesn't work…

shut dust
#

look at your keydown and keyup events

#

keydown - when you are pushing button down, keyup - when you release it.

muted bloom
shut dust
#

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
muted bloom
#

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

shut dust
#

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;

        }

    });

muted bloom
#

i think i fixed that

#

check page

muted bloom
#

okay, so now other problem, how to make user not enter noclip home?

#

i mean, this in a tree for example:

shut dust
#

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.

muted bloom
#

just to not walk into a tree :)

#

(if i don't fall thru floor it's already good)

shut dust
#

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

muted bloom
#

that's what guy from example was using but he was creating cubes and i have .glb…

shut dust
# muted bloom that's what guy from example was using but he was creating cubes and i have .glb...

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.

muted bloom
#

there is something about raycast inside (but can go into a box)

shut dust
#

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

muted bloom
#

(bad at maths moment lol)

lunar lagoon
shut dust
#

you have velocity, so that is something, althrough with that code structure I'm really struggling to understand how it works

lunar lagoon
#

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.