|
0 registered members (),
1,012
guests, and 8
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: keeping the distance between two objects
[Re: jumpman]
#305295
01/14/10 00:54
01/14/10 00:54
|
Joined: Jan 2005
Posts: 330 USA
MatAllum
Senior Member
|
Senior Member
Joined: Jan 2005
Posts: 330
USA
|
Try this (untested):
var dist;
dist = vec_dist(my.x, you.x);
// perform your c_move here //
vec_diff(temp, you.x, my.x);
vec_normalize(temp, dist);
vec_add(temp, my.x);
vec_set(you.x, temp);
Use this snippet in the code for both entities. MY is the entity you're dealing with, YOU is the other entity. If you want collision detection for the correction, replace the last line (vec_set) with another c_move (assuming you use c_move). Two c_m's in per frame cycle per entity is fine - the biped template scripts do this already. Edit: This will make your entities move like an unconstrained hinge - i.e. one entity can move around the other one. This seems like what you're asking for, but if you want the entities' positions relative to each other to be rigid, simply move the second line (vec_dist) to after the move (before vec_diff).
Last edited by MatAllum; 01/14/10 01:00.
|
|
|
|