1
\$\begingroup\$

this question is engine agnostic, I will use the term "object" to refer to entities in my scene.

The scenario is the following:

  • I have 2 entities
  • Entity O is a capsule
  • Entity C is a point

I want to move B toward A's center but stop on A's surface in the less computationally expansive way I can think about.

I figured I'd work out the distance between the center of the capsule and the point on the surface where I should stop and use it as an offset to my destination point (destinationPoint -= direction * computedDistance), but I don't know how to find that distance.

My question is: can you come up with a better way to achieve my goal and if not can you solve the problem I've stumbled upon in my solution?

This is a representation of the secondary problem. In the figure I know the coordinates of C, O, A, B, and I want to know the length of PO or the coordinates of P.

enter image description here

\$\endgroup\$
6
  • \$\begingroup\$ Check for intersection of a line OC with a cylinder expanding capsules' body into infinity. Check if point of intersection P lies within capsules' cylinder body. If not - check for intersection with closest sphere cap of a capsule. \$\endgroup\$ Commented Mar 15, 2018 at 11:55
  • \$\begingroup\$ Hey, thanks for the comment. Do you think this is something ok to do 100 times every frame? \$\endgroup\$ Commented Mar 15, 2018 at 12:00
  • \$\begingroup\$ why would you want to do that so frequently? Anyway - CPUs crunch through math calculations easily. Don't spend time optimising for bottlenecks that are not there. \$\endgroup\$ Commented Mar 15, 2018 at 12:02
  • \$\begingroup\$ I was thinking about having multiple C entities in my application, ok then I will try your soultion out mate :) \$\endgroup\$ Commented Mar 15, 2018 at 12:10
  • \$\begingroup\$ Sorry to bother you, do you also happen to have some good reference on how to get the intersection point on a cylinder? \$\endgroup\$ Commented Mar 15, 2018 at 12:41

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.