0 registered members (),
18,561
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Player sticks on terrain/
#208316
05/26/08 16:47
05/26/08 16:47
|
Joined: May 2008
Posts: 73 Richmond, VA (USA)
coma_dose
OP
Junior Member
|
OP
Junior Member
Joined: May 2008
Posts: 73
Richmond, VA (USA)
|
When moving, my player sticks in certain places on the terrain. Here is the player code, it's part KH movement my Mr. Lancaster, with the gravity from the dude that runs Game Beep:
function pl_character()
{
player = me;
//local variables
var move[3];
var move_result;
var trace_from[3];
var trace_to[3];
var ground_dist;
var anim_per;
//adjust bounding box
wait(1);
c_setminmax(me);
vec_set(my.min_x,vector(-25,-25,-60));
vec_set(my.max_x,vector(25,25,60));
//loop
while(me)
{
temp.x = -1000;
temp.y = 0;
if(key_w && !key_s && !key_a && !key_d){temp.x = camera.pan;}
if(key_s && !key_w && !key_a && !key_d){temp.x = camera.pan + 180;}
if(key_a && !key_s && !key_w && !key_d){temp.x = camera.pan + 90;}
if(key_d && !key_s && !key_a && !key_w){temp.x = camera.pan - 90;}
if(key_w && key_a && !key_d && !key_s){temp.x = camera.pan + 45;}
if(key_w && key_d && !key_a && !key_s){temp.x = camera.pan - 45;}
if(key_s && key_a && !key_d && !key_w){temp.x = camera.pan + 135;}
if(key_s && key_d && !key_a && !key_w){temp.x = camera.pan - 135;}
//calculate directional force
if(temp.x != -1000){temp.y = 20 * time;}
move.x = fcos(temp.x,temp.y);
move.y = fsin(temp.x,temp.y);
//trace floor
vec_set(trace_from,my.x);
vec_set(trace_to,my.x);
trace_to.z -= 500;
ground_dist = c_trace(trace_from,trace_to,ignore_me|ignore_passents|ignore_passable|ignore_sprites|use_box);
//calculate jumping
if(key_space)
{
if(ground_dist < 5)
{
ground_dist = 3;
move.z = 5;
}
}
//gravity
if(ground_dist > 0)
{
accelerate(move.z,(-3 * time_step),0);
if (move.z < (ground_dist * -1))
{
move.z = ground_dist * -1;
}
}
else
{
move.z = -1 * ground_dist;
}
//move player
move_result = c_move(my,nullvector,move.x,ignore_passable|ignore_passents|ignore_sprites|glide);
//calculate rotation
if(my.pan != temp.x && (temp.y > 0))
{
result = ang(temp.x - my.pan);
if(result > 0){my.pan += 30 * time;}
if(result < 0){my.pan -= 30 * time;}
if(ang(temp.x - my.pan) < 0 && result > 0){my.pan = temp.x;}
if(ang(temp.x - my.pan) > 0 && result < 0){my.pan = temp.x;}
}
//rough draft animation
if(temp.y == 0)
{
anim_per += (1 * time_step);
ent_animate(me,"idle",anim_per,anm_cycle);
anim_per %= 100;
}
else
{
anim_per += (move_result * (2 * time_step));
ent_animate(me,"run",anim_per,anm_cycle);
anim_per %= 100;
}
orbit_camera();
wait(1);
}
}
The sticking can be easily noticed because the running animation is linked to the c_move result. I am unsure as to whether this has to do with c_move itself or rather the gravity. I have tried multiple movement code types and the result seems the same as far as the sticking is concerned.
|
|
|
Re: Player sticks on terrain/
[Re: Pappenheimer]
#208330
05/26/08 17:52
05/26/08 17:52
|
Joined: May 2008
Posts: 73 Richmond, VA (USA)
coma_dose
OP
Junior Member
|
OP
Junior Member
Joined: May 2008
Posts: 73
Richmond, VA (USA)
|
Here's the thing: on a flat surface it is above the terrain, but as it ecounters a slope, the bottom corners may dip slightly below, I think that this causes the sticking; however, decreasing the bounding box value results in a different gravity calculation, to the same end. In essesence, decreasing the bounding box value lowers the player into the terrain and the player will still stick on some slopes. I added "-5" to my ground_dist trace and achieved some success, but the sticking still occurs on steep slopes because the corners will still collide with the terrain.
EDIT: I was actually doing some thinking, I'm at work now and can't test it until I get home, but if I decreased the bounding box size by say 10 and then decreased the "-5" to "-10", what I may be left with is a bounding box that is technically off the ground a little and the model being offset to twice that creating the illusion that it is off the ground. I may have phrased this wrong, but I can see the meaning in my mind lol. I will post an update when I give it a test run with corrected code and comments to help other people because I am sure that I'm not the only one with this problem.
EDIT: Er, rather; offset by the same amount...
Last edited by coma_dose; 05/26/08 19:36.
|
|
|
Re: Player sticks on terrain/
[Re: coma_dose]
#208462
05/27/08 15:27
05/27/08 15:27
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Can you post a screenshot with the bounding box visible, before and after the correction?
Hm, I'm a bit irritated. I thought Bret's code carries the model's box _above_ the ground, but this doesn't: "if(ground_dist > 0)"
I don't use the code, so I'm just guessing:
ground_dist IMO must be higher the zero, about 20 or so, depending on the models size and the slopes etc.. If it is zero the collision box always touches the ground, but you should avoid that.
|
|
|
Re: Player sticks on terrain/
[Re: Pappenheimer]
#208516
05/27/08 19:12
05/27/08 19:12
|
Joined: Feb 2005
Posts: 647 Williamsburg, VA USA
draculaFactory
User
|
User
Joined: Feb 2005
Posts: 647
Williamsburg, VA USA
|
The problem with the sticking is solved by way of increasing min_z from -60 to -55 and then adding +5 to the end of the c_trace to get the distance to ground. The result is that the bounding box hovers off of the ground and ground_dist thinks it is on the ground because of +5.
Solving this problem created a new one. The player model can move up steep inclines at a speed that is much faster than normal lol. I just need something that decreases the speed while on a steep incline to make it hard to move up steep slopes, and if the slope is too steep, the player can't move up at all.
Making dreams come true... And being erroneously accused of software piracy by Conitec in the process.
|
|
|
|