Skip to main content
gamedev.net
🔒 Locked

Calculus problem/2d vectors

Started by Hungry Joe 3 replies 1.2k views
Original Post
Hungry Joe
Hungry Joe
THIS MAY BE BORING AND/OR NONSENSICAL. APOLOGIES Hi folks. I'm writing my game in a slightly unconventional way and have come up against a little bit of a maths problem. Instead of doing incremental updates on a per frame basis, each time an event happens to an object in the world I recalculate the formula for the objects position and when I render, i just look at the formula for the time being viewed. This means I can do stuff like absolute collision detection and can rollback time and do stuff like kill a unit ten seconds ago. In theory. So basically an entity has a series of Events objects, which each kick in at a certain point. From this a state consisting of position, direction, velocity, acceleration is generated. So an entity might have these events: ENTITY A Create event @ T=0 position = 0,0 direction = 0,1 (north) velocity = 0 accelleration = 0 Change direction event @T=10 change direction to 1,1 (northeast) Change velocity event @T=10 This would mean the entity starts facting north then at T=10, the unit will start moving at 1 unit per second north east. State objects would be created, and referenced whenever the screen is rendered. I have this up and running. The problem arises when I want to create a second Entity with the following events ENTITY B Create event @ T=0 position = -10,-10 direction = 0,1 (north) velocity = 2 accelleration = 0 Follow entity(a) event @T=0 for this period, the direction travelled should be the direction towards the first entity What I want to happen here is that b is a missile, and its should always point towards the first entity. THis means its position at time T is dependent on the path A takes. If you are smart enough to solve the problem I have, you are probably smart enough to see it at this point. The position of B can be found by: (the overall velocity vector B has taken to time T (call it V)) * T at a time T, B will change its velocity by the vector between A.position and B.position, so I I integrate that, I should get V. Right? Is this right and can anyone do this? It seems pretty fucking hard to me :) I will ask later about the situation where B can only rotate a certain amount per second :) thanks geniuses
0110011001110101011000110110101100100000011011110110011001100110
TheAdmiral
TheAdmiral
This particular problem is somewhat trivial, if I understand correctly, but in the general case, you'd end up with some rather nasty integral equations to solve.

If B is to point at A at all times, then the fact that A travels north-east and A starts north-east of B means that the problem is one-dimensional. Unless there is some rotational inertia that you didn't tell us about, the 'directions' of A and B are meaningless; their velocities paramount.

Initially, A is stationary at the origin, its direction unimportant. At time t=10, it begins to move at unit speed in the direction (1, 1). We'll ignore the energy-conservation issues this raises [rolleyes]. So the position of A is determined by:
p<sub>A</sub> = { (0, 0)                    t <= 10 <sub> </sub>   { (t - 10, t - 10)/sqrt(2)  t >= 10
Now B will initially want to move north-east, as it originates at (-10, -10). At time t=10, A starts moving directly away from B, so B needs not change heading. You never said how B's speed is defined, but implied that it is constantly v=2. If this is the case, then B will collide with A before A starts moving. If you were to reduce this speed so that A blasts off before collision, the two would collide further down the line at t = (sqrt(200) - 10vB) / (vB - 1).

Anyway, whether I've interpreted this correctly or not, I'm pretty confident that you'll quickly get yourself into a serious mess with this deterministic approach. Simply changing one of the parameters would force you to recalculate the time evolution of all the bodies. This will be no simple task when you start introducing accelerations, as second-order integral equations one piecewise-smooth functions are no walk in the park to solve.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Hungry Joe
Hungry Joe
you're absolutely right that it will require a re-calculation after a parameter change. However, these will only be caused by user interaction and interaction with other objects in the game world. The theory is that I can have a second thread calculating and storing these recalculated states forwards in time, and when a user sends an input, the affected calculateds are rolled back and run again.

I'm planning a multiplayer RTS style effort, and I think this method would allow me to do really effective syncronisation between clients, not to mention super duper collision detection.

However I also think i may be barking mad, and the maths effort involved too great. I'm hoping someone can come up with a magic bullet general to the problem of one state being a function of another.
0110011001110101011000110110101100100000011011110110011001100110
TheAdmiral
TheAdmiral
Decoupling an inseparable system of equations is something of a holy grail in mathematics. While you could feasibly find solutions iteratively to the horrible horrible equations that will be generated, it will take much effort on the parts of you and the CPU. I'm afraid there's no magic bullet this time.

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
Vorpy
Vorpy
Entity B is following what is known in mathematics as a pursuit curve. The Mathworld article on pursuit curves gives an analytical solution for the case where entity A is moving directly north (any other solution could be found by rotating the coordinate system, I guess).

Unless this is the most complicated motion your game is going to have, I think you might want to reconsider this idea. There's a reason why even accurate simulators use numerical methods to solve complex systems.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.