[SOLVED] Distance between player and mouse

That which we have discussed in recent posts.

Sure, but I don’t see how it helps with the original problem as both the target position to walk to and the player are already in world space.

Because without collision we can’t get the right World position of the mouse above the player. If i only use the flat boundingBox then the “line” that I want to “draw” passes the mouse on the screen way to far (as you can see on the image that I posted). So if I know the distance in 2D and I can convert this to the distance in 3D then I can “draw” the 3D “line” with good length, from the player to the mouse above or under the player.

There’s no real way of doing this effectively without the collision or a bounding box to intersect with.

The best approximation you could do is to have a plane that is parallel to the camera in orientation and have it’s position the same as the player.

Use screenToWorld to create a ray and intersect with said plane.

The thing is that it seems you already have a world position that the player moves towards. Could you not use that instead?

I do use this point but this is the boundingBox point because there is not always a physical wall or floor in the level. Why is it not possible to use the rotation of the object (the plane) in boundingBox?

Okay, so the player moves towards that point but users the sensors to know when to stop if there is no floor in front of it?

Not sure what you mean by this?

Yes, exactly.

If I could rotate the plane of the bounding box for example 90 degrees (if the player is climbing) I would get the correct point of the mouse above the player and not a point further away in the world.

There are other shapes you can use as well. The bounding box is axis aligned so you can’t rotate it.

However, there is a oriented box which can represent a box in any rotation https://github.com/playcanvas/engine/blob/master/src/shape/oriented-box.js

There isn’t a clear example of how to use this though so you will have to work from source for the moment.

I still don’t think this will give you the result you want with out bugs though. For example if the player is near the top of the ladder, I assume you want your blue arrow to stop at the top of the ladder right?

I don’t know yet how exactly I want to apply it. I had the idea that the further the player "pulls the line out of the character” the faster the character will run. (For that the line should always go to the finger or mouse and not so much the end of the path).

But I think it is better to wait until the new collider functions are available.

This method should work well in that case. Here’s a sample project without using Ammo/Collisions: https://playcanvas.com/editor/scene/906767

I had to make a few changes to the rendering layers and add a second camera to ensure the line and marker was rendering on top of the world.

I am not finished yet, but as far as I can see I can achieve the good result with this example project. So thank you for your input and your effort!

Madrillapp is fine, it’s part of MailChimp which is used for the email service.