|
7 registered members (fairtrader, Quad, miwok, Martin_HH, AndrewAMD, alibaba, dpn),
581
guests, and 0
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Delay bei vec_for_bone und ang_for_bone
#405481
07/31/12 19:55
07/31/12 19:55
|
Joined: Oct 2011
Posts: 3
FFH
OP
Guest
|
OP
Guest
Joined: Oct 2011
Posts: 3
|
Hallo,
ich möchte einen Sprite an ein bewegtes Modell heften. Das Modell ist mit Bones versehen, so dass mir die Routinen vec_for_bone und ang_for_bone geeignet scheinen. Das Modell ist als Entity "wheel" deklariert. Es handelt sich um ein Rad mit Speichen an deren Ende der Sprite angebracht werden soll.
In der action-Routine des Sprites habe ich als Code folgendes fabriziert:
if (my.skill10 == 1.0) { vec_for_bone(_pos, wheel, "Bone2"); _pos.y += 20; vec_set(my.x, _pos.x); ang_for_bone(_angle, wheel, "Bone2"); vec_set(my.pan, _angle); }
... und tatsächlich foltg Position und Ausrichtung dem Modell,... allerdings mit einem unschönen DELAY.
Der Sprite klebt also nicht an seinem Platz, sondern entfernt sich von diesem, wenn das Modell beschleunigt und setzt sich erst nach dem "abbremsen" wieder an die gewünschte Position.
Hat jemand eine Idee, wodurch ein solches Delay verursacht werden könnte und wie mnan es verhindern kann? Die Szene insgesamt ist recht einfach und läuft soft und ohne Ruckeln. Eine Überlastung während des Renderns halte ich daher für ausgeschlossen.
|
|
|
Re: Delay bei vec_for_bone und ang_for_bone
[Re: FFH]
#405485
07/31/12 20:24
07/31/12 20:24
|
Joined: Jul 2002
Posts: 3,208 Germany
Error014
Expert
|
Expert
Joined: Jul 2002
Posts: 3,208
Germany
|
Die klassische Erklärung für dieses Problem ist die Folgende (steht auch im Handbuch, ist aber zugegebenermaßen fast unmöglich zu finden, wenn man das nicht weiß): Funktionen laufen nicht wirklich gleichzeitig. Je nachdem, in welcher Reihenfolge du deine Entities erzeugst, kann es sein, dass deine Sprite-Funktion VOR der anderen läuft. In dem Fall würde sie sich auf die Position der Bones setzen, und DANACH würde sich das Objekt selbst bewegen (und damit wären dann die Bones auch an einer anderen Stelle). Du kannst Abhilfe schaffen, indem du setzt. Oder, wie es das Handbuch sagt: Bad timing, againQ. We have a model entity with a bright red light at it's very centre. For improving the light effect, we've attached a TGA sprite to that model:
action attach_sprite()
{
set(my,BRIGHT); // make light more brilliant
my.roll = 1; // always face the camera
while (1)
{
vec_set(my.x,you.x); // place the sprite at the xyz position of the entity that created it
wait(1);
}
}
action red_model()
{
ent_create("light.tga", my.x, attach_sprite); // attach light sprite
...
patrol() // some movement action
}
We expected that the light sprite is fixed to the center of the model, and moves together with it. However it always seems to lag behind by one frame. And even worse, the model now does not move anymore! What's happening? A. The second problem is easy to fix: We've forgotten to make the light passable. So the model permanently collides with it's own light. Entities attached to other ones should be PASSABLE:
action attach_sprite()
{
set(my,BRIGHT|PASSABLE); // make light more brilliant and passable
... // etc.
But what produces the strange time lag? If two entities influence each other, it's important to keep in mind the order of their two simultaneously running actions. They won't run really at the same time. In the example, during one frame the function scheduler runs first the attach_sprite action, and then the red_model's movement action. Functions that are started first will run first. So the sprite is always placed to the position the red_model had in the frame before. The solution is simple: By changing the order of the actions ...
action red_model()
{
patrol(); // perform move behavior first
ent_create ("light.pcx", my.x, flare_light); // attach light sprite and start it's action after that
}
...the light stays perfectly at the entities' center. We could alternatively use PROC_LATE for changing the order of actions:
action attach_sprite()
{
set(my,BRIGHT|PASSABLE); // make light more brilliant and passable
my.roll = 1; // always face the camera
while (1)
{
proc_mode = PROC_LATE;
vec_set(my.x,you.x); // place the sprite at the xyz position of the entity that created it
wait(1);
}
}
(Hervorhebung von mir)
Last edited by Error014; 07/31/12 20:26. Reason: Zitat korrigiert
Perhaps this post will get me points for originality at least.
Check out Dungeon Deities! It's amazing and will make you happy, successful and almost certainly more attractive! It might be true!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|