startFollow , produces vibration in the game
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 40.3k
- Forks
- 7.2k
- PR merge metrics
- No merged PRs in 30d
Description
In this example, I test startFollow at a slow speed and zoomed in, which is how it looks best.
Then I comment out startFollow and use my function, which I have enabled in a prerender.
https://cell1.tiuvi.com:1029/mp4/startFollowVibration.mp4
In this video, I test my function, which is my least favorite part: having to round the player's x and y positions.
Also, the camera speed needs to be slightly slower than the player's.
https://cell1.tiuvi.com:1029/mp4/newFunctionStartFollow.mp4
If this function could be done natively, it might perform better.
state.events.on('prerender', () => {
const velocity = state.global.player.body.velocity;
const speedPlayerPx = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
// Accedemos a la cámara principal y al jugador
const cam = state.cameras.main;
const player = state.global.player;
const px = player.x;
const py = player.y;
const centerMapX = cam.width / 2
const centerMapY = cam.height / 2
const playerPositionX = px + centerMapX;
const playerPositionY = py + centerMapY
const cameraPositionX = cam.scrollX + centerMapX;
const cameraPositionY = cam.scrollY + centerMapY;
const marginWidth = (cam.width * (cam.zoom * cam.zoom) / 2) * 0.2
const marginHeight = (cam.height * (cam.zoom * cam.zoom) / 2) * 0.2
let moviment = speedPlayerPx === 0 ? 1 : speedPlayerPx * 0.7
if(moviment < 1){
moviment = 1;
}
let newCamX = cam.scrollX;
let newCamY = cam.scrollY;
if ((cameraPositionX + marginWidth) > playerPositionX) {
newCamX = cam.scrollX - moviment;
} else if ((cameraPositionX + cam.width - marginWidth) < playerPositionX) {
newCamX = cam.scrollX + moviment;
}
if ((cameraPositionY + marginHeight) > playerPositionY) {
newCamY = cam.scrollY - moviment;
} else if ((cameraPositionY + cam.height - marginHeight) < playerPositionY) {
newCamY = cam.scrollY + moviment;
}
if (cam.scrollX === newCamX && cam.scrollY === newCamY) {
return;
}
player.x = Math.round(px)
player.y = Math.round(py)
newCamX = Math.round(newCamX);
newCamY = Math.round(newCamY);
cam.scrollX = newCamX;
cam.scrollY = newCamY;
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting Phaser's camera startFollow entry point and reproduce the reported vibration using the linked videos and the slow-speed, zoomed-in setup described in the issue. Determine the intended native follow behavior and verify that camera movement no longer vibrates without requiring the reported manual position rounding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100