# Auto aiming

**URL:** <https://phaser.discourse.group/t/auto-aiming/744>\
**Category:** Phaser 3\
**Created:** [January 14, 2019, 8:37am UTC](https://phaser.discourse.group/t/auto-aiming/744 "2019-01-14T08:37:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![PavelMishin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pavelmishin/32/2128_2.png) [@PavelMishin](https://phaser.discourse.group/u/PavelMishin)\
**Post date:** [January 14, 2019, 8:37am UTC](https://phaser.discourse.group/t/auto-aiming/744/1 "2019-01-14T08:37:50Z")

</div>

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](https://jsfiddle.net/Trobing/7kxuzL9e/48/)

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.

---

<div class="post-metadata">

**Author:** ![iskhomutov](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/iskhomutov/32/1956_2.png) [@iskhomutov](https://phaser.discourse.group/u/iskhomutov)\
**Post date:** [January 14, 2019, 7:24pm UTC](https://phaser.discourse.group/t/auto-aiming/744/2 "2019-01-14T19:24:36Z")

</div>

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%5Cphysics%5Carcade%5Cmove%20to%20pointer.js)  
[http://labs.phaser.io/edit.html?src=src\physics\arcade\move%20to.js](http://labs.phaser.io/edit.html?src=src%5Cphysics%5Carcade%5Cmove%20to.js)

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 14, 2019, 8:14pm UTC](https://phaser.discourse.group/t/auto-aiming/744/3 "2019-01-14T20:14:18Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![PavelMishin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pavelmishin/32/2128_2.png) [@PavelMishin](https://phaser.discourse.group/u/PavelMishin)\
**Post date:** [January 17, 2019, 4:46am UTC](https://phaser.discourse.group/t/auto-aiming/744/4 "2019-01-17T04:46:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PavelMishin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pavelmishin/32/2128_2.png) [@PavelMishin](https://phaser.discourse.group/u/PavelMishin)\
**Post date:** [January 17, 2019, 4:51am UTC](https://phaser.discourse.group/t/auto-aiming/744/5 "2019-01-17T04:51:51Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![PavelMishin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pavelmishin/32/2128_2.png) [@PavelMishin](https://phaser.discourse.group/u/PavelMishin)\
**Post date:** [January 17, 2019, 5:30am UTC](https://phaser.discourse.group/t/auto-aiming/744/6 "2019-01-17T05:30:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PavelMishin](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/pavelmishin/32/2128_2.png) [@PavelMishin](https://phaser.discourse.group/u/PavelMishin)\
**Post date:** [January 17, 2019, 5:38am UTC](https://phaser.discourse.group/t/auto-aiming/744/7 "2019-01-17T05:38:53Z")

</div>

And that’s because I follow official tutorial [http://phaser.io/tutorials/making-your-first-phaser-3-game/part10](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?

---

<div class="post-metadata">

**Author:** ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)\
**Post date:** [January 17, 2019, 4:02pm UTC](https://phaser.discourse.group/t/auto-aiming/744/8 "2019-01-17T16:02:40Z")

</div>

> [@PavelMishin](#):
>
> there is “bomb.allowGravity = false;” in the end of collectStar function!

Yes, that’s a mistake.
