tentone / nunuStudio

Web powered cross-platform 3D, WebXR game engine.
https://nunustudio.org
MIT License
2.13k stars 319 forks source link

How to make a slight strafe movement (left right) when move a mouse? #434

Open petepolyakov opened 4 years ago

petepolyakov commented 4 years ago

Good evening, I wanted to create a slight interactive parallax when you move mouse left or right (camera position moves on one or two axis with flexible limit). I tried to use Orbital and Control. Unfortunately, they can't (so far as I know) make a slight strafe movement with limits. I was wondering if there is any way around.

details

petepolyakov commented 4 years ago

Basically recreating the A and D buttons in FPS games with a limit of "how far camera would slide". I seen in Orbital it's done in regardless of looking left and right, but in my case I wanted to do that strafe camera move.

tentone commented 4 years ago

Hello

Yes this should be faily easy place your orbi controls object inside of a Group object.

Then using a script you can move the group object around using the mouse position.

Check the documentations and the examples on the script page https://www.nunustudio.org/page/learn/basics/02_script/page.html.

The scene looks great

Cheers

petepolyakov commented 4 years ago

You were right, it was just a couple of lines. Works! Thank you! Will research what commands can be used for a slight drag but already the front page look way better!

btw if someone will need it in the future

var object;
function initialize()
{
    object = scene.getObjectByName("MainCamera

");
}
function update()
{
    object.position.x += Mouse.delta.x * 0.0002;
    object.position.y += Mouse.delta.y * 0.0002;
}