Boar movement

Planning and Development

I finally got the boars to face the correct way as they are moving around.  Sometimes I get a little turned around when I have to do straight up trigonometry, and that’s what this was.  Here’s what worked (in pseudocode):

var o = boarObject;

var currentPosition = ...

var newPosition = ...

var direction = newPosition - currentPosition;

o.rotation.y = Math.atan(direction.x / direction.z);

It took me an embarrassing number of tries to get this right, but it’s working now.

***

Edit: After I was sure this was working, I fired up Lyridia on my second test machine and it was still completely broken.  I fumbled around with it for some time before I found a Stack Overflow post that recommended using lookAt.  Instead of trying to calculate the rotation myself based on the direction vector, now I just tell each boar object to lookAt(newPosition); and it works great.  Internally THREE.js must be doing what I was attempting to do, but the THREE.js code actually works, so I’m going to let it handle it. 🙂

***

I had a few hours in the car today to sort of plan out the next steps for Lyridia.  I don’t want to get into all of it now because it’s late, but I’m at the point where some more “game” type functionality is going to be added soon, and once there is something for a player to actually do I might start hunting around for alpha testers just to get somebody on the site.  Exciting stuff.

Leave a Reply

Your email address will not be published. Required fields are marked *