Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 10:32
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 604 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Gravity Problem #75548
05/25/06 17:42
05/25/06 17:42
Joined: Apr 2006
Posts: 265
V
vartan_s Offline OP
Member
vartan_s  Offline OP
Member
V

Joined: Apr 2006
Posts: 265
I'm having a problem which I've tried to solve for quite some time now, with no success. I made a trace code, which gives gravity and allows you to go through terrain, but when you touch the corner of a building you slowly rise to the top of the building! Apart from that it works fine; It only happens when you touch the corner. The ground variable becomes -1 exactly. Here is the code:

action player_entity
{
player = me;
while (1)
{
vec_set (temp, my.x);
temp.z -= 4000;
trace_mode = ignore_passable + use_box + ignore_me + ignore_push;
ground = trace (my.x, temp);
if(ground < 10) {player_speed.z = -trace(my.x,temp);}
else {player_speed.z -= gravity_entity;}
if (ground <= 10)
{player_speed.x = 15 * (key_w - key_s) * time; // move forward / backward
player_speed.y = 10 * (key_a - key_d) * time; // strafe left / right
}
move_mode = ignore_you + ignore_passable;
if ((key_space == on) && (ground < 10))
{
player_speed.z = 7;
}
c_move(me, vector(player_speed.x,player_speed.y,player_speed.z),nullvector, glide + ignore_me);
if ((key_d == on) || (key_a == on) || (key_s == on) || (key_w == on) || (ground > 10))
{
if (weapon_in_play_acc_change < weapon_in_play_max_loss)
{weapon_in_play_acc_change += weapon_in_play_acc_loss_movement;}
} else {
if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off))
{
weapon_in_play_acc_change -= weapon_in_play_acc_gain;
}
}
if ((mouse_left == on) && (weapon_ready == 1))
{
snd_play (bullet_wav, 0, 0);
while (weapon_in_play_pellets_change != 0)
{
weapon_in_play_pellets_change -= 1;
push_factor_change -= 1;
ent_create (bullet_mdl, my.pos, shoot_bullet);
wait(1);
}
camera.tilt += weapon_in_play_up_recoil;
push_factor_change = -weapon_in_play_pellets;
weapon_ready = 0;
weapon_become_ready();
weapon_in_play_pellets_change = weapon_in_play_pellets;
if (weapon_in_play_acc_change < weapon_in_play_max_loss_moving)
{weapon_in_play_acc_change += weapon_in_play_acc_loss;}
} else {
if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off))
{
weapon_in_play_acc_change -= weapon_in_play_acc_gain;
}
}camera.x = player.x;
camera.y = player.y;
camera.z = player.z;
player.pan = camera.pan;
wait (1);
}
}

Only look at the part that looks at gravity. Disregard the rest. Thanks in advance, and sorry if its a noobish question!

Re: Gravity Problem [Re: vartan_s] #75549
05/25/06 19:08
05/25/06 19:08
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Something like that...

Code:

var TraceDist = 4000; // set the distance for tracing

action player_entity
{
player = me;
while (1)
{
vec_set (temp, my.x);
temp.z -= TraceDist;
trace_mode = ignore_passable + use_box + ignore_me + ignore_push;
ground = c_trace(my.x, temp) + my.min_z; // by adding min_z, you get the distance from the "feet" of the model. Remove this if needed.
if (ground <= 0) {ground += TraceDist;} // Here's the magic trick. Trace returns <= zero if the trace immediatly hits a solid. You want to tell it that it really didn't. ;)
if (ground < 10) {player_speed.z = -ground;} // No need for another trace. ;)
else
{player_speed.z -= gravity_entity;}
if (ground <= 10)
{
player_speed.x = 15 * (key_w - key_s) * time; // move forward / backward
player_speed.y = 10 * (key_a - key_d) * time; // strafe left / right
}
if ((key_space == on) && (ground < 10))
{
player_speed.z = 7;
}
move_mode = ignore_you + ignore_passable + glide; //Just another way to do it...
c_move(me, vector(player_speed.x, player_speed.y, player_speed.z), nullvector, move_mode);
if ((key_d == on) || (key_a == on) || (key_s == on) || (key_w == on) || (ground > 10))
{
if (weapon_in_play_acc_change < weapon_in_play_max_loss)
{weapon_in_play_acc_change += weapon_in_play_acc_loss_movement;}
} else {
if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off))
{
weapon_in_play_acc_change -= weapon_in_play_acc_gain;
}
}
if ((mouse_left == on) && (weapon_ready == 1))
{
snd_play (bullet_wav, 0, 0);
while (weapon_in_play_pellets_change != 0)
{
weapon_in_play_pellets_change -= 1;
push_factor_change -= 1;
ent_create (bullet_mdl, my.pos, shoot_bullet);
wait(1);
}
camera.tilt += weapon_in_play_up_recoil;
push_factor_change = -weapon_in_play_pellets;
weapon_ready = 0;
weapon_become_ready();
weapon_in_play_pellets_change = weapon_in_play_pellets;
if (weapon_in_play_acc_change < weapon_in_play_max_loss_moving)
{weapon_in_play_acc_change += weapon_in_play_acc_loss;}
} else {
if ((weapon_in_play_acc_change > weapon_in_play_accuracy) && (mouse_left == off))
{
weapon_in_play_acc_change -= weapon_in_play_acc_gain;
}
}
camera.x = player.x;
camera.y = player.y;
camera.z = player.z;
player.pan = camera.pan;
wait (1);
}
}



Last edited by xXxGuitar511; 05/26/06 15:47.

xXxGuitar511
- Programmer
Re: Gravity Problem [Re: xXxGuitar511] #75550
05/26/06 07:11
05/26/06 07:11
Joined: Apr 2006
Posts: 265
V
vartan_s Offline OP
Member
vartan_s  Offline OP
Member
V

Joined: Apr 2006
Posts: 265
It doesn't work, especially if you try and jump (also terrain) and ground is usually about 4000 (I had to change the ground parameters to 4000 rather than 10, but there are still problems. I also keep falling through terrain (terrain is a model). If I changed c_move to ent_move would it work? So that the bounding box would not come go inside a solid object. Or is there any way to use the bottom of the polygons to trace rather than the box?

Re: Gravity Problem [Re: vartan_s] #75551
05/26/06 15:49
05/26/06 15:49
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
I didn't know you were using a model for terrain, that kinda changes things a bit...

change the trace() to a c_trace. Do not use ent_move(), You have to use c_move().

*-Updated changes in blue ^ (just the "C_" on C_TRACE())


xXxGuitar511
- Programmer
Re: Gravity Problem [Re: xXxGuitar511] #75552
06/06/06 08:45
06/06/06 08:45
Joined: Mar 2006
Posts: 724
the Netherlands
Frits Offline
User
Frits  Offline
User

Joined: Mar 2006
Posts: 724
the Netherlands
My player also keeps falling through the terrain (I have changed the terain into a model).
I tried to solve this problem with the c_trace, but when I include the line:
my.fall_distance = c_trace(my.x,temp,trace_mode)+my.min_z;
the player keeps falling through the terrain.
When I include the line:
if(my.fall_distance<=0) {my.fall_distance+=trace_dist;}
the player can't move anymore.

Here is my
Code:

//-------------------
// player move action
//-------------------

//uses: Walk_Anm_Speed, Run_Anm_Speed, Strafe_Anm_Speed, Jump_Walk_Run,
//uses: Battery, Armor, Health, Ammo, Battery_max, Armor_max, Health_max, Ammo_max, Keys, falling,
//uses: fall_distance, jumping, jump_hight, idle_percent, walk_percent, run_percent,
//uses: land_percent, jump_percent, temptilt,
//uses: move_vec_x, move_vec_y, move_vec_z
action player_move
{
player=me;
wait(2);

my.falling=0; //not falling
my.jumping=0; //not jumping
my.jump_hight=0; //jump hight=0

my.idle_percent=0;
my.walk_percent=0;
my.run_percent=0;
my.land_percent=0;
my.jump_percent=0;
my.temptilt=0;
camera.genius=player;
shift_sense=int(my.run_anm_speed);
my.enable_scan = ON;
my.event=player_events;

while(my.health>0)
{
vec_set(temp,my.x);
temp.z-=trace_dist;
trace_mode=ignore_me+ignore_sprites+ignore_passable+activate_sonar+use_box;
my.fall_distance = trace(my.x,temp); // original line
// my.fall_distance = c_trace(my.x,temp,trace_mode)+my.min_z;
// if(my.fall_distance<=0) {my.fall_distance+=trace_dist;}

// check if jumping
if (my.jumping !=0)
{
jump_handling();
}

// check if falling
fall_handling();

// check if player pressed jump X and isn't already juping or falling
if (key_x)
{
if(my.jumping==0 && my.falling==0 && my.fall_distance<1)
{
my.jumping=1+key_shift; //if holding shift key when hit jump means we were running
my.move_vec_z=20*time; //starting jump velocity
}
}
// if not jumping or falling we can move
if(!my.falling && my.jumping==0) //if falling=0 then !falling=-1, or true that I'm not falling
{
my.move_vec_x=(key_force.y)*int(my.walk_anm_speed)*time;
my.move_vec_y=(key_comma-key_period)*int(my.strafe_anm_speed)*time; //strafing
}
// turn players facing
if(mouse_mode==1)
{
player.pan=(player.pan-(key_force.x)*5*time);
}
else
{
player.pan=(player.pan-(key_force.x+mouse_force.x)*5*time)%360;
}

// animations

// animate jump
if (my.jumping !=0)
{
jump_animate();
}
else //other animations
{
if (my.falling == 1) // animate falling
{
fall_animate();
}
else // animate stand walk and run
{
If (my.move_vec_x == 0 && my.move_vec_y == 0) // stand
{
stand_animate();
}
else // our movement animations will go here
{
if (key_shift) // either shift key is being pressed run aniamtion
{
run_animate();
}
else // shift key is NOT being pressed so we are walking
{
walk_animate();
}
}
}
}

// entity moves
move_mode=ignore_you+ignore_passable+ignore_push+activate_trigger+glide;
ent_move(my.move_vec_x,NULLVECTOR);

update_camera();

wait(1);
}
}



I hope someone can help me with this problem.

Regards,
Frits


I like to keep scripting simple, life is hard enough as it is.
Regards,
Frits
Re: Gravity Problem [Re: Frits] #75553
06/06/06 18:17
06/06/06 18:17
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Before you add min_z to fall_distance, make sure that the trace did not return 0 (hit nothing) or 1 (in ground - or somethin like that). like this:

Code:

my.fall_distance = c_trace(my.x, temp, trace_mode);
if (my.fall_distance == 0)
{my.fall_distance = trace_dist;}
my.fall_distance += my.min_z;



NEW: Ok. I updated the code a bit. Just put this at the beginning of your while() loop. Or at least before anything that uses the trace_distance variable.

Last edited by xXxGuitar511; 06/07/06 15:42.

xXxGuitar511
- Programmer
Re: Gravity Problem [Re: xXxGuitar511] #75554
06/07/06 10:34
06/07/06 10:34
Joined: Mar 2006
Posts: 724
the Netherlands
Frits Offline
User
Frits  Offline
User

Joined: Mar 2006
Posts: 724
the Netherlands
Quote:


if (my.fall_distance == 0)
{my.fall_distance = trace_dist;}
my.fall_distance += my.min_z;





Where do I put this (after IDK... what do you mean by that?)

Regards,
Frits


I like to keep scripting simple, life is hard enough as it is.
Regards,
Frits
Re: Gravity Problem [Re: Frits] #75555
06/07/06 15:42
06/07/06 15:42
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
*Updated above code...


xXxGuitar511
- Programmer
Re: Gravity Problem [Re: xXxGuitar511] #75556
06/07/06 16:05
06/07/06 16:05
Joined: Mar 2006
Posts: 724
the Netherlands
Frits Offline
User
Frits  Offline
User

Joined: Mar 2006
Posts: 724
the Netherlands
Thanks, I will try it out tomorrow.

Regards,
Frits


I like to keep scripting simple, life is hard enough as it is.
Regards,
Frits
Re: Gravity Problem [Re: Frits] #75557
06/08/06 07:32
06/08/06 07:32
Joined: Mar 2006
Posts: 724
the Netherlands
Frits Offline
User
Frits  Offline
User

Joined: Mar 2006
Posts: 724
the Netherlands
No, didn't help, still falling through the terrain model.

Regards,
Frits


I like to keep scripting simple, life is hard enough as it is.
Regards,
Frits
Page 1 of 2 1 2

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