3d camera mouse drag and scroll example

0 favourites
  • 9 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • Been messing about with 3d lately.

    Here is an example of 3d camera controls for moving and rotating with the mouse along with drag scroll and adjustable smoothness, useful for lots of types of 3d games.

    There is one bug however and that is sometimes when you are looking directly down the camera will spin 360 when rotating. I believe this has to do with looping degrees from 0 to 360, but haven't been able to find where it is in the code.

    If you are able to fix this one issue, please repost the capx.

    https://www.dropbox.com/scl/fi/fi7wjoxmc3fd1tfmetvqm/2d3dcam-3.c3p?rlkey=s6bhk5osk8meirgs59qmhs1hy&raw=1

    Thanks.

  • You'd get a similar jerk in motion when using anglelerp and the target angle differs more than 180 degrees. Best i can tell you're easing the positions and getting angles from that so it's indirectly the same thing.

    One possible solution could be to use a variable for the current angle and add the change of the mouse position to that and lerp another angle to that. Here's a minimal example showing the difference between normal angle lerping and that. Could be something to try at least.

    dropbox.com/scl/fi/q8cf0o8htz5h8dubo25e1/rotationEasing.capx

  • Thanks for the example. I'll make the modifications and see if it helps.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Here's a modification that includes the rotation fix. I apologize, the events ended up looking a bit different since I tried simplifying a lot while I was trying to pinpoint what was causing the bug.

    * All mouse input is on the ui layer now.

    * As a side effect the drag move formula is a bit uglier since it has to rotate the mouse position delta by the rotation. Before you used mouse position from the 3d layer but that was giving NaN's when tilt was 0. Reverting back to use mouse position from the 3d layer has it's merits though since the point on the ground where you started dragging would match where you dragged to.

    * It now only moves the target object directly and the cam object eases toward the target. Also it eases position, zoom, tilt and angle. That was the main change that enabled the fix.

    * The lerping is now framerate independent. It was a small change basically using exp(-100*dt) instead of 0.2*60*dt.

    * The 3d camera position is calculated in one go with spherical coordinates which incorporates zoom, angle and tilt. It should end up the same as what you had.

    dropbox.com/scl/fi/ljuplixdxjtghe23ijzdo/2d3dcam_Test.c3p

  • Thanks very much for your help.

    Its a shame the mouse no longer moves to the drag point, that was actually something i worked hard to implement.

    Also the rotation issue doesn't seem to be fixed for me, the camera goes crazy now. It seems to do this unpredictable as well.

    I tried to capture what i was seeing.

  • Oh strange since it’s smooth on my end. I’ll have to test again. Maybe add a trace of the mouse path to debug.

    Either you’re moving the mouse in a path I didn’t test or the easing is flawed on other refresh rates? You can try to set t to 100*dt or something instead of what it has now and see if that affects things.

    It’s probably easy to switch it back to moving relative to where it clicked on the ground. Could also rotate based on where we clicked on the ground too, but then we’d need a separate control for tilt.

    Edit:

    Did you change any of the values? When I had t=exp(-100*dt) the ease was super gradual.

  • I haven't altered any of the values, just ran the file. I'll do some more tests.

    It would be great to have a solid example to give to the community as it could be useful so a lot of 3d game types.

  • Fixed.

    * drag based on where the mouse clicks now like you had it before.

    * also fixed the janking craziness. Turns out near a tilt of 90 things could go haywire. Fix was to limit tilt to range 1 to 89.

    dropbox.com/scl/fi/ljuplixdxjtghe23ijzdo/2d3dcam_Test.c3p

  • Very impressive as always.

    Everything seems to be working flawlessly now.

    Thanks very much. It should be included with the official C3 examples.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)