Issues on other devices

Does anybody know how to modify this headbob script so the camera bobs the same on all devices, I think I need to use dt or smth, thanks in advance

https://playcanvas.com/editor/code/1172985?tabs=162690692,160420310

Also if somebody could help me understand what dt is and how it works that would be great!

Hi @Brent_Reddick!

It looks like you already do. Maybe you shouldn’t, but I’m not sure.

Ok so the bob moves at the same speed on all devices but on some it looks like the bob way far up and way far down more than it should, how do I fix this?

Ah okay, I think you use a fixed value which maybe looks bigger on a smaller screen?

If that’s the case, you maybe can do something with the screen height of the device.

1 Like

Ok, how would I do that? Also the problem is still there when the device is not in full-screen on the game page but I definitely think it is worth a try

like my Chromebook and my mac work find and they have different screen sizes

What kind of device it is not working fine?

A windows I believe

I don’t think the operating system changes the behavior of this.

Do you know the issue?

I don’t actually know the size of the screen that has the bug, I noticed it while watching somebody play the game

Difficult to debug the problem without any resource to compare the result.

1 Like

How would I “you maybe can do something with the screen height of the device.” ?

If the problem is indeed related to the screen size, you will need to adjust the values ​​of the code below and multiply them by the screen height or something similar. You will need to do some research yourself on how to get the screen height or canvas height.

image

I did some searching and tried this but it made the bob go so high and low that even the minimum is not enough, I don’t know what to do

HeadBobController.prototype.FootStepMotion = function () {
    var pos = new pc.Vec3(0, 0, 0);
    pos.y += Math.sin(this._time * this._frequency) * this._amplitude * window.innerHeight;
    //pos.x += Math.cos(this._time * this._frequency / 2) * this._amplitude * 2;
    return pos;
};

Maybe something like * (window.innerHeight / 10)?

I had to make the number 500 but it works on my device, but I have a hard time understanding how doing this would make head bob amplitude the same for all devices, I’m not the best at mental math

Because I’m looking at the equation and I used a website to calculate my inner window height and it was 612, but if a device’s inner window height is not 612 the equation would come out to a different number

My guess was the head bob looks bigger on smaller screens, so that’s why I suggested to multiply it with the screen size so the head bob is less on a smaller screen to make it looks the same as on a bigger screen.

1 Like