-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sprite.distance & world.raycast implementation #314
Conversation
In p5.js there is already a function for calculating the distance between two points.
dist(spriteA.x, spriteA.y, spriteB.x, spriteB.y) There's also spriteA.pos.dist(spriteB.pos) But I do like that use of your function would be far simpler. There's already spriteA.distanceTo(spriteB) It also might be nice to make p5's dist(spriteA, mouse) |
|
Thank you! Also I forgot to say since p5play's Merging your pull request! |
Edit: Actually maybe it should be a limit function, ie. if the sprite is a wall it returns true to stop the ray. |
I also want |
I like that you used radius and direction for this function instead of a second point. Great for p5play ease of use! |
@codingMASTER398 I added some additional info to your planck issue report: piqnt/planck.js#270 |
I'm going to switch the input param order to match Unity's as well. https://docs.unity3d.com/ScriptReference/Physics.Raycast.html |
First time contribution - Some of my formatting may not be up to spec, and the minified version isn't currently included.
This PR aims to fix #280, as well as a pet peeve of mine being the lack of Sprite.distance() function.
Sprite.distance(otherSprite)
Returns the distance to the other Sprite. How this isn't already implemented is odd to me.
world.raycast
An implementation atop of the world.rayCast (don't get them confused! I don't know how to override the other one and still use it) that returns the closest sprite from a position and direction of a ray.
Due to limitations I've encountered in the past, I'm still unable to get Planck to return a list of all rays & find the closest one simultaneously. Even with
Sprite.distance
, I wasn't able to get it working.Thus, the function currently only returns one "hit" (true/false), "sprite", "point", and "normal".
This can be remedied with the optional
excludeFunction
, detailed in a comment in the PR.Here's a sketch demonstrating the functionality.