Rotate Physics object with mouse and freecam input

A lot of times I don’t talk much, but on the right topic, I talk too much.

1 Like

Givo… I just thought of something.

Our Scene object has been loaded-up with some useful “observables”.

https://doc.babylonjs.com/api/classes/babylon.scene#onpointerobservable

OnPointerObservable is a universal “catch it all” observer… and your handler function would need to “sniff” to see what happened… turn, drag, possibly swipe/gestures, mousewheel, etc.

There’s also specific-action observables… like onPointerMove, down, up, pick, etc.

If I were you, I would leave FreeCameraMouseInput alone, for now. Keep it default.

Instead… write a bunch of custom scene-based pointer-event handlers… using those observers.

Start with little handlers… that simply console.log(“mouse moved”) and try to determine WHEN a user is dragging on-canvas. Actually, you’re a pointer-lock junky, so maybe you don’t need to listen-for drags… only pointer-moves.

We also have scene.actionManager to help us determine when user is leftbutton/rightbutton dragging or wheeling. (geez, does ANYONE do right-button dragging, these days?)

Anyway, with custom observers/handlers… set on these handy BJS SceneObject observables… you SHOULD be able to get all the power you need… WITHOUT having to deep-hack the camera’s mouseInput code.

Try that, first. While testing, or at other times, you may wish to NOT attach the camera to the canvas. Observers might quit working, then, though. Maybe scene.activeCamera = null;? I dunno… I’m just tying to think of ways to keep the camera frozen… and still listen for scene pointer observables.

Using scene observables… is a much better solution than the input hacking. I think I might have lead you astray by suggesting it. If you need help adding some basic observer handlers to the scene object, just holler. It’s simple, though.

scene.onPointerObservable.add(function(d,s){
     console.log("mouse did something!", d, s);
}

d and s are a couple of automatically-arriving objects that might have useful info on them.

There’s no results when searching Scene API for ‘mouse’ or ‘wheel’… just pointer stuff. No right-button or middle-button observables, either… but we can get them from scene.actionManager, if needed.

Give it a sniff, if you please. I think these scene-observer methods are much wiser than hacking that freeCamMouseInput crap.

Some keyboard stuff, seen, too. hmm. peace-out!

I’ve been thinking too. A cube isn’t the best thing for a hitbox because of the corners. (go against a wall, and not be able to turn) What if we making a a cylinder diameter 1. height 1, and call it good. then we could move it bas on the CAMERA’s y rotation, as a cylinder is uniform all the way around. The problem with that is we would have to combine the cylinder’s x an z rotation and the camera’s y. just something that might make it hard but could work.

I used an event listener that tracked mouse movement. Worked like a charm. thanks for trying to help @Deltakosh!

Note to self:

  1. Have a repro to my issue in the playground
  2. More details
  3. No TMI
2 Likes

Good thinkings. Remember that sphereImpostors can be used on boxes, and etc etc… mix and match, have a good time.

There’s other options, because of Cannon’s meshImpostor option/feature.

First… you could use BABYLON.MeshBuilder.CreateSphere( “mysphere”, {a gazillion settings allowed here} );… to make a flat-bottom sphere! Round on all sides… except on the bottom where we need good friction surface-area.

Then use meshImpostor instead of sphereImpostor. GRUESOME!!!

If that isn’t scary enough… Documentation/Polyhedra_Shapes.md at master · BabylonJS/Documentation · GitHub

Feel free to use one of many shapes there, and then use meshImpostor. MeshImpostor is “supposed-to” wrap a tight collider around ANY mesh, as best it can. Could be perf-heavy on complex models… but should be fine on the shapes we’re talking-about, here.

Yuh yuh, yuh. Good, juicy experimenting! May your horse be with you.

Hey Givo, I just remembered something important. CannonJS MeshImpostors ONLY collide with spheres. So, your ground and ramps would need to be made from “sheets of little spheres”, which is likely implausible for you. Sorry, I forgot. Demo.

Also, the flat-bottom spheres made by MeshBuilder… cannot have their flat sides “capped”. “unclosed” is mentioned repeatedly, but no talk of “closed”.

I hope you haven’t been pursuing that avenue, and got stumped.

Nah, I’ve been working on other things. like this

Ok.

I need to show you one more possibility… in the physics dept. CannonJS cloth. @RaananW made this:

https://www.babylonjs-playground.com/#1M67K8#11

Real nice demo. You can click the cloth, too.

Later, I did some tweaking… turned it into this:

https://www.babylonjs-playground.com/#1M67K8#16

Wait a bit… sphere will move thru mesh. Not much different… just a bit naked.

Lastly, the latest version, using LockJoints instead of DistanceJoints:

https://www.babylonjs-playground.com/#1M67K8#25

Yes, I’m manually force-positioning a green sphere that has a physicsImpostor… a semi-unwise thing to do with potential unpredictable results. I should use setLinearVelocity on its impostor, instead.

Main point: Think about 5-9 of these spheres… hooked together by physics joints like these spheres… to make a platform for your camera. None of the spheres in your little “physics magic carpet” could roll-over or tip-over, even if they were box impostors. The joints that attach the impostors… to their fellow impostors in the magic carpet… won’t allow ANY significant impostor rotation.

Likely, if you DID build a small “camera raft” with these things, you would ONLY setAngularVelocity and setLinearVelocity on the sphere in the center, and the “outrigger?” spheres would also (automatically) turn/move… because of the joints connecting them to center-sphere.

Anyway, I just wanted to make sure that you had this “thing”… in your toolbox… in case you wanted to give it a try. In a way, it is similar to your “extra sphere for intersect testing” - method… but here… extra spheres are connected to main sphere… by joints, not parenting. AND… using sphere impostors on the surrounding spheres, but box impostor on the main/center mesh… CAN DO… and might work goooood.

There are a half-dozen TYPES of physics joints, and they don’t care what type of impostors are attached to both ends of them. :slight_smile: Joints sometimes have settings like stiffness and springyness.

Ok, have fun with your capsule building. I showed you in the last post… how to make half-spheres. Why not just position/parent two half spheres… to the butt-ends of a cylinder… and mergeMesh as wanted? Seems easier, but might have odd UV’s.

Capsule impostors DO show-up here and there… in the physics engines, and if not available, can be built out of compounds (like 2 sphereImpostors+?)

Last I heard, the ORDER of adding impostors… is important, for compounds.

I think… FIRST add parent’s impostor. THEN parent children to parent mesh. THEN add impostors to children. (I hope I remember that correctly). Don’t set parent on an impostor’d mesh. Parent it first, then set its impostor. :slight_smile: kbyeee

1 Like

Nice idea with the cloth, but I get ~15 fps at max. (aka not good for an fps!) How many do you get?

Right now I’m working on a player model and other things.

Hopefully a demo by april!

Yeah. That will improve when you lower the impostor/joint numbers. I think you can do 5 “nodes” and maybe only 4 joints (a 4-legged bug). You might need 4 more… to go bugfoot-to-bugfoot around the outside.

Lots of options, and few have tried things like this… ever before. “Givo’s Bug-Base Camera QuadPod” v1.0 :slight_smile:

is the v1.0 a reference to the “capsule make v1.0-1.1” I made?

Nah. It just means that YOU were the FIRST one to ever build such a thing (magic carpet camera pod). You might be mentioned in a History-of-3d book, someday. Perhaps become a senator. :slight_smile:

Lots of folks have made capsules, including Tylenol Inc. :wink: Unlikely you’ll get famous with CapsuleMaker.

I’m pretty sure I was the first to do the capsule thing. But yeah, if I was first, everyone would be v"my version":“their version”
like:
my version: 5.13
their version: 2.1

total version: 5.13:2.1

https://dualbox.com/apps/capsule-geometry/production

https://doc.babylonjs.com/playground/?code=capsule

1 Like

Hmm. Well, I had fun making the function!

Don’t be sad. Perhaps keep going, and be the first to add CreateCapsule to MeshBuilder.

No parenting is allowed there… just formulas to “grow” a capsule.

Pryme8 was sort-of pushing you toward using MeshBuilder and adding a new CreateCapsule function there. You WOULD be the first to add it to MeshBuilder.

It’s not very easy for certain types of people, unfortunately. And MeshBuilder has “structure rules” that you need to follow… in order to make YOUR new ‘Create’ function… match other ‘Create’ functions that are already installed there.

I hope I didn’t rain on your parade. Make that MeshBuilder version, and you WILL get mini-superstar status. :smiley:

1 Like

if you take too long I’m gonna hop on it :wink: just wanted to give you a second to shine and learn something in the process.

@Wingnut I want that dualbox capsule buffer method now, that is the first one I have seen with that many arguments. Pretty cool.

You didn’t. I’m just took it the wrong way.:upside_down_face:

Feel free, as I’ve got this project (you know the one that this topic was made for?) and another project(more serious, and is not gonna be done anytime soon.) This topic’s project is a side project of mine, as my main one is for something else.(DM me if you wanna know what it is, as it is not related to these forums or babylon.js in general)

if you wanna message me about your projects to get some advice/input/reactions my door is always open.

1 Like

Nah, I meant you can DM me if YOU would like to know about my big project.

Anyway, I have 2 more issues so I’m gonna make another post soon.