View Single Post
  #2  
Old 07-16-2014, 11:03 PM
Zaela_S
Hill Giant
 
Join Date: Jun 2012
Posts: 216
Default

Vector math, yay.

I'm not sure if the server codebase has a complete vector implementation, and vector math always confuses me, but I believe you'd want something like this pseudocode:

Code:
Vector a(pusher->GetX(), pusher->GetY(), 0);
Vector b(target->GetX(), target->GetY(), 0);

Vector c = a - b;
c.normalize();
c *= MakeRandomFloat(0, 0.1f); //can leave out if the amount of push should equal 1 unit

b -= c;
Where b ends up being the X+Y position of the target pushed back by the randomized number of units away relative to the pusher's X+Y position. For NPCs you'd just update their position to that and then send out position update packets. Not sure how to apply to Clients; same kind of thing might be okay.

I leave it to you to look up the vector operations if needed cuz I hate em. Maybe we already have functions for that stuff though, too lazy to look right now.
Reply With Quote