How to move entity with dynamic rigidbody towards the player

So I have a script that is intended to move a dynamic entity towards the player but it doesnt work very well, and I do not quite understand the script because someone wrote it for me. Is there another way to achieve this or to fix this script?


What is the result? That makes it easier to tell what to change. Not sure if this code is a recommend way anyway, but it looks like it could work.

There is also an example project that can be useful.

Well currently the script has 3 problems:

the entity will sometimes suddenly stop or has random speed changes
the entity will teleport forward a a meter or so for seemingly no reason
the entity slowly builds up speed and becomes faster

The scene you have provided me does exactly what I need it to, but I seem to have trouble converting it to track an entity instead of a mouse raycast.

I tried frankensteining the script in that scene and I managed to get it to move forward on its own but it currently moves in a straight line. I cant seem to get it to look at the camera entity and move towards it

You need to use the position of the entity.


It does move towards the player now, but it does not look at the player

Please note that looAt() works in the opposite way.

no i mean it looks in one direction
I even added another entity that has the “halo” billboard script but even that doesnt look at the player while attached to the entity.

If you check the example project you will see that looAt() is done on a child entity, because you can’t use lookAt() on an entity with a dynamic rigidbody. (On your previous screenshot you where doing this).

Does that mean entities with a dynamic rigidbody cannot use look at or they cannot be looked at by another entity?

They cannot use lookAt() directly.

The example project is showing how you can still use lookAt() on a dynamic entity using a child entity (because you cannot use lookAt() directly on an entity with a dynamic rigidbody).

If you are referring to this project: PlayCanvas 3D HTML5 Game Engine then im not sure what you are talking about because the script is used on an entity with a dynamic rigidbody and it seems to work fine.

Because it use lookAt() on the child entity this.modelEntity and not on the entity with the dynamic rigidbody this.entity.

You are correct and I fixed it