|
2 registered members (3run, AndrewAMD),
667
guests, and 1
spider. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
variables in while-loop
#410642
11/06/12 17:19
11/06/12 17:19
|
chris_oat
Unregistered
|
chris_oat
Unregistered
|
Hi, ok here it is: i have this while-loop inside my player-move-code:
while(1)
{
abs_movement_x_0 = player.x;
abs_movement_y_0 = player.y;
...code...
c_move(my,vector(player_movevector[0],player_movevector[1],0),nullvector,IGNORE_PASSABLE|IGNORE_SPRITES|GLIDE | IGNORE_PUSH);
...code...
abs_movement_x_1 = player.x;
abs_movement_y_1 = player.y;
//Distanz der Vektoren berechnen
abs_movement_x_1 = abs_movement_x_1 - abs_movement_x_0;
abs_movement_y_1 = abs_movement_y_1 - abs_movement_y_0;
abs_movement_res = sqrt(abs_movement_x_1*abs_movement_x_1 + abs_movement_y_1*abs_movement_y_1);
wait(1);
}
the code above works. var abs_movement_res gets updated correctly. But now i changed the c_move into:
pXent_move (my, vector(player_movevector[0],player_movevector[1],player_movevector[2]), NULL);
after this, the variable stay always the same it doesnt get updated. Does anyone know why? Thanks for any input!
|
|
|
Re: variables in while-loop
[Re: Superku]
#410649
11/06/12 17:39
11/06/12 17:39
|
chris_oat
Unregistered
|
chris_oat
Unregistered
|
hmmm, so what could i do about it?? i thought no matter how the entity gets moved, it just checks for the players x, y coordinates every frames. why would C_move be any different then pXent_move, both just move the entity...
|
|
|
Re: variables in while-loop
[Re: Superku]
#410678
11/07/12 05:35
11/07/12 05:35
|
chris_oat
Unregistered
|
chris_oat
Unregistered
|
Fixed it! I believe the c_move was so slow that it actually caused a delay between the variables above and below the command, while the pXent_move was way faster that the variables stays the same and thus didnt get new values. I now wrote a new void function where I wrote the variables and just put a Wait(1); instead of the c_move  It may not be the best solution, but it does work!
while(1)
{
abs_movement_x_0 = player.x;
abs_movement_y_0 = player.y;
wait(1);
abs_movement_x_1 = player.x;
abs_movement_y_1 = player.y;
//Distanz der Vektoren berechnen
abs_movement_x_1 = abs_movement_x_1 - abs_movement_x_0;
abs_movement_y_1 = abs_movement_y_1 - abs_movement_y_0;
abs_movement_res = sqrt(abs_movement_x_1*abs_movement_x_1 + abs_movement_y_1*abs_movement_y_1);
wait(1);
}
|
|
|
Re: variables in while-loop
[Re: ]
#410679
11/07/12 06:26
11/07/12 06:26
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Well, now it does exactly what you thought would be the problem... Also, this is not how Lite-C works, but congrats on fixing the symptoms.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: variables in while-loop
[Re: WretchedSid]
#410687
11/07/12 09:00
11/07/12 09:00
|
chris_oat
Unregistered
|
chris_oat
Unregistered
|
yes, unfortunally thats the only thing i was able to at the moment, fixing the symptoms, but not the cause... im not that good in coding, and i never will be but if you can give me a better solution and explane it to me how it works iam very thanksful 
|
|
|
Re: variables in while-loop
[Re: ]
#410689
11/07/12 09:45
11/07/12 09:45
|
Joined: Feb 2010
Posts: 320 TANA/Madagascar
3dgs_snake
Senior Member
|
Senior Member
Joined: Feb 2010
Posts: 320
TANA/Madagascar
|
I think you can achieve the same thing using - init old and new position variables
- set new position
- calculate delta
- save current position in old_pos variable
function main()
{
var x = 0, y = 0;
// New position
var abs_movement_x0 = 1;
var abs_movement_y0 = 1;
// Last position
var abs_movement_x1 = 1;
var abs_movement_y1 = 1;
while(1)
{
// Set new position
abs_movement_x0 = x;
abs_movement_y0 = y;
///pXent_move()...............
// Dist (delta = new - old)
var dx = abs_movement_x0 - abs_movement_x1;
var dy = abs_movement_y0 - abs_movement_y1;
var length = sqrt(pow(dx, 2) + pow(dy, 2));
// Save Current position for next frame
abs_movement_x1 = abs_movement_x0;
abs_movement_y1 = abs_movement_y0;
DEBUG_VAR(length, 10);
// Simulate PhysX update
var speed = 5;
x += speed * time_step;
y += speed * time_step;
wait(1);
}
}
Last edited by 3dgs_snake; 11/07/12 09:45.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|