|
Collision and walking up sloped surfaces
#175361
12/30/07 08:06
12/30/07 08:06
|
Joined: Mar 2002
Posts: 580 San Francisco
clone45
OP
User
|
OP
User
Joined: Mar 2002
Posts: 580
San Francisco
|
Hello! I'm trying to perfect some third-person movement code and I'm running into issues when my character attempts to walk up inclines at an angle. My gravity code and movement code must be to blame, but the solution eludes me. My gravity is pretty standard: I trace to the ground and place the model on the ground. If the model is within a block, I rise it up out of the block. I'm using version 7.06. I posted a video on youtube the shows the choppy movement while moving up an incline diagonally: http://www.youtube.com/watch?v=6_wOHp-0EjcGoing down the incline is no problem. Neither is going straight up. Here's a cut down version of my movement code: Code:
// Calculate the distance from the ground and position the player accordingly.
vec_set(vec1_from,my.x); vec_set(vec1_to,my.x); vec1_to.z -= 500;
result = c_trace(vec1_from, vec1_to, IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX);
// Handle Gravity
if (result > 0) { // Acceleration due to "gravity" accelerate(move_to_vector.z, (-3 * time_step), 0); // fall // If the acceleration of the fall would result in the player being moved below the ground, shorten // the fall so that the player is put directly on to the ground. if (move_to_vector.z < (result * -1)) { move_to_vector.z = result * -1; } }
// If the player is within a block, push them up out of the block
if (result < 0) { // Trace from about 1/2 the player height down to the ground. vec1_from.z += half_player_height; result = c_trace(vec1_from, vec1_to, IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX); move_to_vector.z = (half_player_height - result) * -1; // rise out of block }
// If the player is exactly on the ground, don't apply any gravity or floating if (result == 0) { move_to_vector.z = 0; } move_friction = 0.2;
// Move the player c_move(me, move_to_vector, nullvector, GLIDE|IGNORE_SPRITES|IGNORE_PASSABLE);
Thanks for any advice! - Bret
|
|
|
Re: Collision and walking up sloped surfaces
[Re: clone45]
#175362
12/30/07 19:57
12/30/07 19:57
|
Joined: Mar 2005
Posts: 969 ch
Loopix
User
|
User
Joined: Mar 2005
Posts: 969
ch
|
[offtopic] Hey...are you back in 3dgs business??? That would be cooool  [ontopic] What happens if you try to pan your player using c_rotate?
|
|
|
Re: Collision and walking up sloped surfaces
[Re: Loopix]
#175363
12/30/07 20:55
12/30/07 20:55
|
Joined: Mar 2002
Posts: 580 San Francisco
clone45
OP
User
|
OP
User
Joined: Mar 2002
Posts: 580
San Francisco
|
[ontopic] Hi loopix! Thanks for the help. I do pan my player using c_rotate, but it doesn't make any difference. I'll post my entire move code below. I've tried a TON of different things to try to solve the problem. So far, no luck. [offtopic] Yes! I'm back! I found myself with some free time and I'm working on a "Goblin Fishing Game". It's an old project that I always wanted to make. It will be mission based fantasy fishing. Ha ha ha. My goal is to keep it as simple as possible. No pathfinding. No AI. As few animated 3d models as possible. It's good to be back. Here's my entire movement code. I really want to get this perfect. Once I'm done, I'll be happy to share it with the community. Some of it is based off of other movement and animation code, such as the Kingdom Heart's movement tutorial. Code:
action move_me() { VECTOR temp; VECTOR move_to_vector; VECTOR result; VECTOR my_pan; VECTOR vec1_from; VECTOR vec1_to; var camera_distance = 300; var camera_height = 160; var aspeed; var bspeed; var half_player_height = my.max_y ; var mouse_pan_speed = 2; var distance_to_ground; var KEY_PAN_SPEED = 14; c_setminmax(me); // watched = my; move_to_vector.x = 0; move_to_vector.y = 0; move_to_vector.z = 0; while(1) {
// Check scroll wheel camera_distance += mickey.z * mouse_scroll_speed * time_step; // Adjust camera height based on mouse y axis (optional) // camera_height += mouse_force.y * mouse_tilt_speed * time_step; vec_set(my_pan,nullvector); vec_sub(my_pan, vector(accelerate(aspeed, 5 * mouse_force.x, 0.7),0,0)); // pan the camera c_rotate(my,my_pan,IGNORE_PASSABLE); // Get key input from the player for character movement accelerate(move_to_vector.y, (key_d * strafe_speed * time_step * -1), 0.8); // strafe left accelerate(move_to_vector.y, (key_a * strafe_speed * time_step), 0.8); // strafe right accelerate(move_to_vector.x, (key_w * run_speed * time_step), 0.8); // go forward accelerate(move_to_vector.x, (key_s * run_speed * time_step * -1), 0.8); // go back // Calculate the distance from the ground and position the player accordingly. vec_set(vec1_from,my.x); vec_set(vec1_to,my.x); vec1_to.z -= 500;
distance_to_ground = c_trace(vec1_from, vec1_to, IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX); // Handle jump using spacebar if (key_space) { if (distance_to_ground < 2) { distance_to_ground = 1; move_to_vector.z = 5; } } // Handle Gravity
if (distance_to_ground > 0) { // Acceleration due to "gravity" accelerate(move_to_vector.z, (-3 * time_step), 0); // fall // If the acceleration of the fall would result in the player being moved below the ground, shorten // the fall so that the player is put directly on to the ground. if (move_to_vector.z < (distance_to_ground * -1)) { move_to_vector.z = distance_to_ground * -1; } } // If the player is within a block, push them up out of the block if (distance_to_ground < 0) { // Trace from about 1/2 the player height down to the ground. vec1_from.z += half_player_height; distance_to_ground = c_trace(vec1_from, vec1_to, IGNORE_ME|IGNORE_PASSENTS|IGNORE_PASSABLE|IGNORE_SPRITES|USE_BOX); move_to_vector.z = ((half_player_height - distance_to_ground) * -1); // rise out of block } // If the player is exactly on the ground, don't apply any gravity or floating if (distance_to_ground == 0) { move_to_vector.z = 0; } // Move the player c_move(me, move_to_vector, nullvector, GLIDE|IGNORE_SPRITES|IGNORE_PASSABLE);
// Move camera and handle animation move_camera(camera_distance, camera_height); handle_animation(1); // Calculate new animation if (abs(move_to_vector.x) > .5 || move_to_vector.y != 0) //if we are moving { if (my.animblend == stand) //if our current animation is stand { if (key_shift == 1) { my.blendframe = walk; } else { my.blendframe = run; } } if (my.animblend == run && key_shift == 1) { my.blendframe = walk; } if (my.animblend == walk && key_shift == 0) { my.blendframe = run; } } else { if (my.animblend > stand) //if we aren't moving and our current animation is walk or run, blend and cycle the stand animation { my.blendframe = stand; } } wait(1); } }
|
|
|
Re: Collision and walking up sloped surfaces
[Re: clone45]
#175365
12/30/07 21:33
12/30/07 21:33
|
Joined: Sep 2003
Posts: 5,900 Bielefeld, Germany
Pappenheimer
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
|
Other suggestions: Did you try different slopes? I mean: different steep slopes? Although, I'm sure you already checked that 'cause you're familiar with the old collision system: Where is the origin of the model?
Did you already look into this:
from the manual:
"USE_AABB P Uses an axis aligned bounding box (AABB) for collision, rather than an oriented bounding box (OBB). The AABB system is faster, but ignores the entity orientation on USE_BOX, treats models and sprites as boxes, and requires a BSP level. See collision for the difference between both systems. "
That's all I can think of and my suggestions could be pretty useless, because you already looked for that and I don't use the new collision systems yet. I still use A6.60 and trace instead of c_trace and such.
|
|
|
Re: Collision and walking up sloped surfaces
[Re: Pappenheimer]
#175366
12/30/07 21:48
12/30/07 21:48
|
Joined: Mar 2002
Posts: 580 San Francisco
clone45
OP
User
|
OP
User
Joined: Mar 2002
Posts: 580
San Francisco
|
Hallo Pannenheimer, I just tried USE_AABB, but there was no difference. I may go back and try trace and ent_move, just to see if it works. That's not a bad idea. I've made another video showing how the panning is causing my entity to get temporarily stuck, which makes the movement very choppy: http://www.youtube.com/watch?v=ardKYaVstmA
|
|
|
|