Lewis Mills
Lewis Mills

Reputation: 1

Make an object walk to the mouse click position

I have two classes; one player class and one enemy, I want to make the player walk to wherever the mouse is clicked. How can I get around doing this???

I have attempted to use PVector, however I have never been taught to use these before so I have little knowledge on these.

Upvotes: 0

Views: 100

Answers (1)

George Profenza
George Profenza

Reputation: 51857

You can can start with the Easing example: easy enough without PVectors.

The idea is to use a ratio of the difference between the current position and target position as an increment to the current position.

Daniel Shiffman's Nature of Code is excellent for what your after, be sure to check out:

  1. The Vector Chapter (available on youtube)
  2. The Autonomous Behaviours Chapter(available on youtube)

In the future I recommend posting your approach as a simplified code snippet. Also be sure to checkout the Tour

P.S. Don't always need tutors to show you everything,just need to learn how to learn. Nowadays there's a wealth of really easy to understand resources out there. Ideally you'd be learning most of the things on your own, tutors just guide/steer you in the right direction.

Upvotes: 2

Related Questions