Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, OptimusPrime), 15,359 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
User
clone45  Offline 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-0Ejc

Going 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 Offline
User
Loopix  Offline
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 Offline OP
User
clone45  Offline 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] #175364
12/30/07 20:59
12/30/07 20:59
Joined: Mar 2002
Posts: 580
San Francisco
clone45 Offline OP
User
clone45  Offline OP
User

Joined: Mar 2002
Posts: 580
San Francisco

PS: You may be on to something about the c_rotate. If I be careful not to rotate the character while he's walking, there are fewer "hiccups" in the movement. If I vigorously rotate the character while he's walking, the character gets stuck often. However, I am using c_rotate, so I'm not sure what's up.

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 Offline
Senior Expert
Pappenheimer  Offline
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 Offline OP
User
clone45  Offline 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

Re: Collision and walking up sloped surfaces [Re: clone45] #175367
12/31/07 18:31
12/31/07 18:31
Joined: Mar 2002
Posts: 580
San Francisco
clone45 Offline OP
User
clone45  Offline OP
User

Joined: Mar 2002
Posts: 580
San Francisco
I finally figured it out. My initial bounding box was rectangular and wasn't centered at the entity's origin. I manually set the entity's bounding box like so:

wait(1); // wait 1 frame after creation
vec_set(my.min_x,vector(-7,-7,-20));
vec_set(my.max_x,vector(7,7,20));

And now I have perfect movement. I'll post my movement code in the tutorial area later today.

Thanks!!
- Bret

Re: Collision and walking up sloped surfaces [Re: clone45] #175368
12/31/07 21:05
12/31/07 21:05
Joined: Mar 2002
Posts: 580
San Francisco
clone45 Offline OP
User
clone45  Offline OP
User

Joined: Mar 2002
Posts: 580
San Francisco


Moderated by  HeelX, Spirit 

Gamestudio download | 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