If you want to drag and drop the camera normally
you have to tick
Otherwise the drag ratio will not match
For example, if you drag a distance of 100 pixels, the camera may only move 40 pixels, etc.
very cheating
Because 3. The x version does not have the zoom attribute of the camera, so it cannot be calculated
The current camera can only modify othroHeight (only for 2d games
Damn it, it won’t work if it’s changed to another model,
or it won’t work if it’s changed to a different scaling ratio in the game.
Grass
, I should consider the screen scaling problem after changing the model
******8, I Finally got it done.
First of all, we don't consider the model issue. After all, if we can hook this Align, then in fact, it is normal to drag and drop the game at the beginning.
Then what we have to solve is, if we need to zoom in or zoom out the camera, what should we do if the dragging is abnormal.
After repeated experiments, I came to this conclusion
Suppose the current OthroHeight is 100, then if we adjust the height of OthroHeight to 80 after zooming the camera
Then the actual distance when we drag is (80/100)*distance
Really hateful, I have been experimenting for so long!
The solution is as follows:
/**摄像机拖动 */
BeDraging(e: EventTouch) {
let TouchPos = e.getLocation()
let Touchpos3 = new Vec3(TouchPos.x, TouchPos.y)
let TheCamera = this.TheGameManager.GameCamera;
// let WorldPos = new Vec3;
// TheCamera.camera.screenToWorld(WorldPos, Touchpos3)
let realPos2 = Touchpos3
//获取移动距离和角度
let distance = MathTools.GetDistanceBetweenTwoPoints(this.TouchStartPos, realPos2)
let radian = MathTools.GetRadianBetweenTwoPoints(this.TouchStartPos, realPos2)
console.log(TheCamera)
let X = Math.cos(radian) * distance * TheCamera.camera.orthoHeight / 320//320这个是一开始的摄像机的高度,这个可以自己用一个变量来调
let Y = Math.sin(radian) * distance * TheCamera.camera.orthoHeight / 320
console.log('距离' + distance)
TheCamera.node.setWorldPosition(new Vec3(this.CameraStartPos.x - X, this.CameraStartPos.y - Y));
}