Workaround for Physics gravity direction not adjusting when rotating device

Hi @jonathan, I’ve the 90° problem in landscape mode: I need to have the gravity always at the bottom to simulate things falling…any workaround? Would be nice in the future to have an option about this. Thanks! :smile:

Would having 2 layouts, one portrait , one for landscape with gravity direction changed on those work?

Yes, but how? Hype manages different screen sizes, but it doesn’t base the decision to show a layout or another in relation of the landscape or portrait mode…if I got it right, of course. It means, you can have a 1024px screen because you’re in a desktop computer (always portrait) or in an iPad in landscape mode, so you cannot be sure, you need to detect it from the accelerometer (event.orientation).

I had in mind something like this:

But if is possible to do it natively, even better! :smile:

anybody? @Daniel?

That’s true: Though this appears like a ‘portrait’ iPad, it’s really the measurement of the width of the device (any device).

One option is to reload the scene on device rotation (which would trigger an ‘onresize’ event). This could be run ‘on scene load’ for your scene.

window.onresize = function(event) {

	// reload the current scene to reset 'gravity' 

It doesn’t work…it reloads the scene but the gravity is still rotated by 90° :frowning: Could you send me a working example? Thanks! :wink:

Here’s an example: (14.8 KB)

It gets the current scene, and reloads it:

var currentscene = hypeDocument.currentSceneName()

window.onresize = function(event) {
	hypeDocument.showSceneNamed(currentscene, hypeDocument.kSceneTransitionInstant)

If you activate “control gravity with device tilt” it doesn’t work :frowning:

@Daniel it doesn’t work with device tilt active, that’s what I need: if I turn the phone/tablet the gravity must turn by 90° and remain always in the bottom…

Hmm sorry but I’m not sure how to resolve this. At this time Physics may need a page reload to reset the gravity directions unfortunately.

But I cannot make your example working with tilt active…maybe I’m missing something. It works with your mobile/tablet? :confused: