1 Replies - 1138 Views - Last Post: 22 October 2011 - 07:29 AM Rate Topic: -----

#1 danm36  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 06-June 09

A simple calculation that's infuriatingly difficult - UnrealScript

Posted 21 October 2011 - 01:45 PM


While this could be considered a general coding question, it's roots are in game code (UnrealScrip). I have trying to work out a single equation for three hours now and it's beginning to REALLY annoy me. What I need is an object that goes towards another object (This case, a point in front of the player) at an increasing speed, and if the object is beyond a certain distance, not move at all (Ie, a magnet attraction system of sorts)

Now, the variables that I've got to play with are the object's trajectory in vector format to get to the point (Infuriatingly, I cannot use it's position, at least I don't think so), the maximum distance in float format and any other number.

The trajectory can be divided or multiplied, but cannot be the multiplier or divisor. It can only add and subtract with other vectors.

Now, I have managed to get the object to move towards the player with a decreasing rate, but I cannot for the life of me inverse the calculation.

//MovVec -> The vector indicating movement - VECTOR
//fMaxDist -> The maximum distance allowed - FLOAT - 1000
//fSmoothRate -> Another function to help in smoothing the movement - FLOAT - 2
//finMovVec -> The final vector from which the Move() function acts on - VECTOR

finMovVec = MovVec / smoothRate; //(Moves towards us at a decreasing rate) WORKS
finMovVec = smoothRate / MovVec; // ILLEGAL (float / vector)
finMovVec = MovVec * smoothRate; // Too fast!
finMovVec = MovVec - (MovVec / smoothRate); //Same as first
finMovVec = MovVec - ((MovVec * smoothRate) / (fMaxDist / MovVec)) //This and anything like this either brake or result in the first function...somehow. Or a constant velocity throughout)

If I can just get it to move towards the player at an increasing rate, I can probably work out the distance limitator.

If I can solve this by modifying the locational values before hand, that would still be good.
MovVec = DestLoc - Location;
//DestLoc is correct, Location is the objects current location

For those of you who know UnrealScipt may say 'Why not use SetLocation()?', well, I've tried and that resulted in some other issues, so I have to resort to 'MoveSmooth()' :(

Even suggestions will help greatly. I will provide any other information required (Though that should be enough)


Is This A Good Question/Topic? 0
  • +

Replies To: A simple calculation that's infuriatingly difficult - UnrealScript

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: A simple calculation that's infuriatingly difficult - UnrealScript

Posted 22 October 2011 - 07:29 AM

have you thought of employing different functions for different bahaviors? Clearly there are different conditions when you expect objects to attract each other over repelling them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1