Collision

Posted By: Mythran

Collision - 03/05/11 22:42

How can i make the player react to models the same way
it reacts to blocks?

Thanks
Posted By: 3run

Re: Collision - 03/05/11 22:55

Set POLYGON flag on static models and use USE_POLYGON in your c_move instruction.
Posted By: Redeemer

Re: Collision - 03/05/11 23:08

If you use the USE_POLYGON flag in your c_move instruction, the entity will perform polygon-based collision detection with everything. To only have this behavior with a single object, use the POLYGON flag on the static models as 3run suggested.
Posted By: Mythran

Re: Collision - 03/05/11 23:18

So how can i add c_move in here?

Thanks



action my_player
{
var walk_percentage; // controls the "walk" animation speed
var stand_percentage; // controls the "stand" animation speed
var climb_percentage; // controls the "climb" animation speed
var movement_speed; // player's movement speed
player = my; // I'm the player
//my.narrow = on;
c_setminmax(my);
my.ambient = -50; // play with the ambient value (-100...100)
my.transparent = on; // the player could be transparent
my.alpha = 100; // but will be opaque if the camera doesn't run into obstacles
my.skill41 = my.camera_height; // store the height of the camera in relation to player's origin
my.skill42 = my.camera_distance; // store the distance to the camera
if (my.health == 0) {my.health = 100;} // default health points = 100
if (my.camera_height == 0) {my.camera_height = 50;} // default camera_height value = 50
if (my.camera_distance == 0) {my.camera_distance = 250;} // default camera_distance value = 250
if (my.player_speed == 0) {my.player_speed = 3;} // default player_speed = 6
if (my.player_inertia == 0) {my.player_inertia = 0.5;} // default inertia = 0.5
if (my.player_rotation_speed == 0) {my.player_rotation_speed = 3;} // default player rotation speed = 5
if (my.player_climbing_speed == 0) {my.player_climbing_speed = 5;} // default player climbing speed = 5
if (my.dist_to_ground == 0) {my.dist_to_ground = 0;} // default distance between player's feet and the ground = 6 quants
if (my.pan_rotation_speed == 0) {my.pan_rotation_speed = 0.6;} // default camera rotation speed (pan) = 0.8
if (my.tilt_rotation_speed == 0) {my.tilt_rotation_speed = 5;} // default camera rotation speed (tilt) = 7
if (my.foot_step_distance == 0) {my.foot_step_distance = 59;} // default foot step distance = 59
while (my.health > 0) // as long as the player is alive
{
// rotate the player using the mouse, "A" and "D" or "cursor left" and "cursor right"
player.pan -= my.player_rotation_speed * mouse_force.x * time - 1.1 * ((key_cul || key_a) - (key_cur || key_d));
camera.x = player.x - my.camera_distance * cos(player.pan); // keep the camera behind the player
camera.y = player.y - my.camera_distance * sin(player.pan); // at the distance given by camera_distance
camera.z = player.z + my.camera_height + 0.8 * sin(my.skill46 * 3.6); // and above the player; 3.6 gives the head weaving amplitude
if (abs(ang(camera.pan) - ang(player.pan)) > 3) // need to rotate the camera quickly?
{
camera.pan += (player.pan - camera.pan) * my.pan_rotation_speed * time; // then do it!
}
else // no need for sudden camera rotations?
{
camera.pan += (player.pan - camera.pan) * my.pan_rotation_speed * 0.33 * time; // then rotate a bit slower
}
camera.tilt += my.tilt_rotation_speed * mouse_force.y * time; // the camera can tilt freely
my.camera_distance = min (max (my.camera_distance, 5), 1000); // camera_distance can have values between 5 and 1000
vec_set (temp.x, my.x); // copy player's position to temp
temp.z -= 5000; // set temp.z 5000 quants below player's origin
distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box); // compute the distance to ground

my.skill22 = my.player_speed * ((key_w || key_cuu) - (key_s || key_cud)); // move the player using "W" and "S" or "cursor up" and "cursor down"
my.skill21 = my.skill22 * time + max (1 - time * my.player_inertia, 0) * my.skill21; // compute speed
movement_speed.x = my.skill21 * time; // time correct the speed

movement_speed.y = 0; // don't move sideways
// the "space" key or the right mouse button are pressed and the player isn't jumping already?
if (((key_space == on) || (mouse_right == on)) && (now_jumping == 0))
{
perform_jump(); // then perform the jumping!
}
if (((key_space == off) && (mouse_right == off)) || (now_jumping == 0)) // space or the RMB aren't pressed anymore?
{
jump_height = max(0, jump_height - 12 * time); // use a smaller falling speed (15) for (potential) smaller jumps
if ((jump_height == 0) && (key_space == off) && (mouse_right == off)) // the player has touched the ground?
{
reached_height = 0; // then allow it to jump again
}
}
// my.dist_to_ground = 6, experimental value, puts player's feet on the ground
movement_speed.z = - (distance_to_ground - my.dist_to_ground) + min (200, jump_height);
movement_speed.z = min(4, movement_speed.z); // limit the movement speed on the z axis
movement_speed.z = max (-20 * time, movement_speed.z); // 20 = falling speed
if ((key_ctrl == on) && ((key_cuu == on) || (key_w == on))) // trying to climb up
{
vec_set (content_dist.x, player.x);
vec_set (temp, vector(20, 0, -20)); // check the content 20 quants in front of the player, 20 quants below its origin (-20)
vec_rotate(temp, vector(player.pan, 0,0));
vec_add (content_dist.x, temp.x); // content_dist is now set at player's feet, 20 quants in front of them
if (content (content_dist) == content_solid) // there's a wall in front of the player?
{
movement_speed.z = my.player_climbing_speed * time; // then start climbing!
}
}
my.skill47 += c_move (my, movement_speed.x, nullvector, glide); // move the player
if (my.skill47 > my.foot_step_distance) // adjust my.foot_step_distance (by default, we've got a step sound every 59 quants)
{
if ((jump_height == 0) && (movement_speed.z == 0)) // not jumping and not falling?
{
snd_play(step_wav, 20, 0); // then play the foot step sound
my.skill47 = 0; // reset the distance (increase the precission)
}
}
if (jump_height == 0) // the player isn't jumping?
{
if ((key_w == off) && (key_s == off) && (key_cuu == off) && (key_cud == off)) // the player isn't moving?
{
ent_animate(my, "stand", stand_percentage, anm_cycle); // play the "stand" animation
}
else // the player is moving?
{
if ((key_ctrl == on) && (content (content_dist) == content_solid)) // climbing?
{
// use a real "climb" animation here; I've only got "finish_him" for this model (although it looks good enough imo)
ent_animate(my, "attack", climb_percentage, anm_cycle);
}
else // not climbing?
{
ent_animate(my, "walk", walk_percentage, anm_cycle); // then play the "walk" animation
}
}
walk_percentage += 8 * ((key_w || key_cuu) - (key_s || key_cud)) * time; // 10 = animation speed
climb_percentage += 8 * time; // 10 = animation speed
jump_percentage = 0; // always start jumping with the first frame
}
else // the player is jumping
{
if (ascending == 1)
{
jump_percentage = jump_height / 2; // playing frames 1...50
stand_percentage = 0;
}
else // descending, playing frames 51...100
{
jump_percentage = min(100, (200 - jump_height) / 2); // limit the animation frame to 100
}
ent_animate(my, "jump", jump_percentage, anm_cycle); // play the "jump" animation
}
stand_percentage += 0.5 * time; // 5 = animation speed
avoid_obstacles(); // run the function that avoids camera collisions with the relief
wait (1);
}
// the player is dead here
my.skill40 = 0; // use skill40 to control the "death" animation
while (my.skill40 < 90) // don't play all the animation frames because the result doesn't look too good
{
ent_animate(my, "death", my.skill40, null);
my.skill40 += 2 * time; // "death" animation speed
camera.roll -= 0.3 * time; // rotate the camera
camera.tilt += 0.8 * time; // make it look up high in the sky
wait (1);
}
my.passable = on; // the corpse will be passable from now on
}
Posted By: Redeemer

Re: Collision - 03/06/11 00:39

First of all, use the [code] tags so that we don't have to try decoding a block of unspaced code.

But on to the question: c_move is already in the code. Just put the USE_POLYGON flag at the end of it.
Posted By: Mythran

Re: Collision - 03/06/11 07:51

Well, it all stays exancly the same as before..
Could be done anything else?
Posted By: 3run

Re: Collision - 03/06/11 08:27

Ohh my God... Dude, do u understand how ur script above works?
Posted By: Mythran

Re: Collision - 03/06/11 08:50

Well, i'm no scripter, and although it's very explained, i'm very limited at
making changes...
I even added enable_polycollision = 2; at main function... but nothing...
So i guess the answer is no.

So if you guys would be more detailed i would be gratefull.

Thanks for you're comprehension.
Posted By: 3run

Re: Collision - 03/06/11 08:54

Dude, u can't make game without understanding at least 60 % of script. Learn workshop, it'll take u about 3 - 5 hours to finish it.
Start from something smaller, make simple movement, try to add USE_POLYGON to it, and see how it changes. There is no other way to learn.
Posted By: Mythran

Re: Collision - 03/06/11 09:02

But i only need this piece of script to work... nothing else...
I always had a problem with collisions, as you might see from other posts...

I just cant seem to get collisions to work...
Is it so complicated?
Posted By: 3run

Re: Collision - 03/06/11 09:04

Not complicated, but very tricky. Not only beginners having problems with collusions.
Posted By: Mythran

Re: Collision - 03/06/11 09:10

You need any help? Just getting started with GS?
Go here: http://badcom.at.ua/
Feel free to ask anything at formspring! My profile is KMRobert

well what if i say i'm just starting with GS and i need some help? tongue
Posted By: 3run

Re: Collision - 03/06/11 09:16

You need to go through workshops, before asking for help. If I'll help you right now, there will be no sense, cause you wouldn't be able to understand.
Posted By: Roel

Re: Collision - 03/06/11 11:46

@ Mythran

in the entity's properties window, you have a list of flags
such as transparent, nofog, nofilter etc.
you also have a flag called "polygon".

If you click this flag for static entities, they will behave 'as blocks do'.
I don't know if this is what you want, could be a misunderstanding,
but it involves no programming. just a single flag laugh

it is actually the same as some users already said
Posted By: Mythran

Re: Collision - 03/06/11 13:21

Well that is what i want, but the only problem is that it won't work...

The player is supposed to climb walls when you press ctrl, and it works
great on block, but in the terrain when you press ctrl he tryed to climb,
it seems he believes it to be a wall, the player just walks over a tent
as if it had no height...

And in the block next to the tent everything works perfect..

Here is a demo and you'll see what i mean:

http://www.2shared.com/file/COfOml4Y/Demonium.html

Thanks
© 2024 lite-C Forums