Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
0 registered members (), 1,012 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
keeping the distance between two objects #301615
12/12/09 01:10
12/12/09 01:10
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
hey everyone!

In C-Script, would anyone know how to keep two objects at a certain distance from each other, but still be able to move and readjust themselves to keep that distance?

I want to build a simple skeleton/particle system. For example, a hand object would stay 100 quants away from the elbow object at all times. But you could move the hand object, and the elbow object would follow, and vice versa.

I made a brute force method of the above, but its dependant on the frame rate (when the framerate drops the entites break apart).

Is there a simple formula to keep two objects at a certain distance to each other?

Re: keeping the distance between two objects [Re: jumpman] #302168
12/17/09 04:22
12/17/09 04:22
Joined: Dec 2008
Posts: 1,660
North America
Redeemer Offline
Serious User
Redeemer  Offline
Serious User

Joined: Dec 2008
Posts: 1,660
North America
Just use Helghast's ragdoll system.


Eats commas for breakfast.

Play Barony: Cursed Edition!
Re: keeping the distance between two objects [Re: Redeemer] #302443
12/19/09 15:28
12/19/09 15:28
Joined: Mar 2007
Posts: 112
MikeS Offline
Member
MikeS  Offline
Member

Joined: Mar 2007
Posts: 112
if u use a model for your skeleton, why dontuse bones?

Greetings

Mike

Re: keeping the distance between two objects [Re: MikeS] #302508
12/20/09 00:31
12/20/09 00:31
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
i use bones for my models, and ragdoll laugh

however i wanted to be able to play with the distance between two objects, possibly for a cloth system, or a chain system without physics objects. (having more than around 7-8 articulated ragdolls can bog your system down)

Re: keeping the distance between two objects [Re: jumpman] #302532
12/20/09 10:42
12/20/09 10:42
Joined: Mar 2007
Posts: 112
MikeS Offline
Member
MikeS  Offline
Member

Joined: Mar 2007
Posts: 112
Im sorry, i still dont know where your problem lies :-)

ok, what about

anyvar = vec_dist(my.x,your.x);

if (anyvar < anything)
{
move away from you
}
if (anyvar > anything)
{
move closer
}

maybe u could use something like this?

Greetings Mike

Re: keeping the distance between two objects [Re: MikeS] #302639
12/21/09 02:14
12/21/09 02:14
Joined: Apr 2002
Posts: 1,246
ny
jumpman Offline OP
Serious User
jumpman  Offline OP
Serious User

Joined: Apr 2002
Posts: 1,246
ny
hey MikeS,

Ive definitly tried that, it ends up making the two particles shake uncontrollably. frown

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
M
MatAllum Offline
Senior Member
MatAllum  Offline
Senior Member
M

Joined: Jan 2005
Posts: 330
USA
Try this (untested):

Code:
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.
Re: keeping the distance between two objects [Re: MatAllum] #305297
01/14/10 01:31
01/14/10 01:31
Joined: Feb 2009
Posts: 2,154
Damocles_ Offline
Expert
Damocles_  Offline
Expert

Joined: Feb 2009
Posts: 2,154
Just use the code, where the objects "shake uncontroled",
and use them as ancor objects.

Now use them to move the actual objects
-for each coordinate, each frame-, using such a formula:

x = xAncor * 0.9 + x * 0.1;

This will result in x moving smootly towards the ancors x
position (also when this moves), but remove the fast "shakes"


---

But its actually better to not change the distance based on a fixed
boundary value. This will lead to a resonance if each object is dooing this.

Better is a code:

Myself -for each other object

if distance < threshold :
move to opposite direction by
(threaholddistance - actual distance) * (threaholddistance - actual distance)

So the closer they are over the minimum distance, the faster they bounce to the other direction.



Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1