Auto aiming

Hi! I try to make the one object move to another object by setting velocity. I assume that the velocity.x should be movingObject.x - targetObject.x, and the same for “y”. That works in Phaser 2, but now, when I tried to reproduce this for the third version, it seems like the endpoint of movingObject have some offset relatively to targetObject. Why this happens and how to fix this?

Here is jsfiddle

And another question - why is changing the bounce of ball (in the same example) change the moving behavior of object? I thought it used for computing just during colliding, not during motion.

Speaking of moving one object to another you can check this phaser examples
http://labs.phaser.io/edit.html?src=src\physics\arcade\move%20to%20pointer.js
http://labs.phaser.io/edit.html?src=src\physics\arcade\move%20to.js

1 Like

it seems like the endpoint of movingObject have some offset relatively to targetObject.

I think that’s just the effect of gravity. Unless you alter a sprite’s origin, its x and y are the coordinates of its center, so that vector should be correct.

why is changing the bounce of ball (in the same example) change the moving behavior of object? I thought it used for computing just during colliding, not during motion.

That happens in the linked fiddle because the ball is created w/ y === 0 so it bounces off the world bounds immediately.

1 Like

Thank you for reply, but it’s a little bit different - moveTo methods updates destination point with target object position updated, I want to destination point stay origin - something like bullet behavior, not following.

I think that’s just the effect of gravity. Unless you alter a sprite’s origin, its x and y are the coordinates of its center, so that vector should be correct.

Gravity is disabled for moving object, and the origin was not changed.

That happens in the linked fiddle because the ball is created w/ y === 0 so it bounces off the world bounds immediately.

thank you, i really haven’t taken it into account

Oh, I figured it out, I have applied “allowGravity = false” to the sprite object itself, but not to the body!

And that’s because I follow official tutorial http://phaser.io/tutorials/making-your-first-phaser-3-game/part10 - there is “bomb.allowGravity = false;” in the end of collectStar function!
So is this a tutorial issue, or I’m not fully understand some concept?

Yes, that’s a mistake.