# Odd error with moveToObject

**URL:** <https://phaser.discourse.group/t/odd-error-with-movetoobject/9699>\
**Category:** Phaser 3\
**Created:** [May 30, 2021, 11:29pm UTC](https://phaser.discourse.group/t/odd-error-with-movetoobject/9699 "2021-05-30T23:29:14Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Milton](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@Milton](https://phaser.discourse.group/u/Milton)\
**Post date:** [June 4, 2021, 6:36am UTC](https://phaser.discourse.group/t/odd-error-with-movetoobject/9699/4 "2021-06-04T06:36:09Z")

</div>

See a previous topic:

> [@GameObject "jumps" through collision objects](https://phaser.discourse.group/t/gameobject-jumps-through-collision-objects/9677/7):
>
> I don’t know, but you can copy the arcade code, which is trivial: var angle = Math.atan2(y - gameObject.y, x - gameObject.x); speed = DistanceBetween(gameObject.x, gameObject.y, x, y) / (maxTime / 1000); gameObject.body.velocity.setToPolar(angle, speed); (use the [actual](https://github.com/photonstorm/phaser/tree/v3.51.0/src/physics/arcade/ArcadePhysics.js#L515) code, this is just the relevant stuff)

Create your own moveToObject function (by copying the Arcade code).  
Use Vector2 setToPolar and Matter setVelocity.

If you want it to work for both physics types, you can check if moveToObject exists, else use your own function. I guess you also shouldn’t use ‘gameobjectdown’, since that can mean anything, like UI or whatever. I would attach ‘pointerdown’ to each Child (or at least check what I clicked on).

---

_[View the full topic](https://phaser.discourse.group/t/odd-error-with-movetoobject/9699)._
