void Vehicle::seek() { PVector *target = player->getLocation(); PVector *desired = PVector::sub(target, location); desired->normalize(); desired->mult(maxspeed); PVector *steer = PVector::sub(desired, velocity); steer->limit(maxforce); applyForce(steer); }
void Mover::update(PVector *mouse) { //Example 1.10: Accelerating towards the mouse PVector *dir = PVector::sub(mouse,location); dir->normalize(); dir->mult(0.3); acceleration = dir; //Example 1.9: Motion 101 (velocity and random acceleration) //acceleration->random2D(); //acceleration->mult(0.3); //Example 1.8: Motion 101 (velocity and constant acceleration) velocity->add(acceleration); velocity->limit(topspeed); location->add(velocity); }