Is there any way to stop 2 entities from overlapping each other? tried platform but it did not work.
no what i mean is normally you can walk right through other entities when you are on the same z level but oi want like street fighter where you can not walk through other entities you will be blocked if you get too close.
if(f < sprites_loaded)
{
// var "z" takes into account whether it has a setlayer set, whether there are other entities on
// the same "z", in which case there is a layer offset, whether the entity is on an obstacle, and
// whether the entity is grabbing someone and has grabback set
z = (int)e->position.z; // Set the layer offset
if(other && e->position.y >= other->position.y + other->animation->platform[other->animpos][PLATFORM_HEIGHT] && !other->modeldata.setlayer)
{
float zdepth = (float)( (float)e->position.z - (float)other->position.z +
(float)other->animation->platform[other->animpos][PLATFORM_DEPTH] -
(float)other->animation->platform[other->animpos][PLATFORM_Z] );
if(
e->link // Linked to entity.
&& ((e->modeldata.grabback && !e->grabbing) // Have grab back AND not grabbing.
|| (e->link->modeldata.grabback && e->link->grabbing) // Linked has grab back and is grabbing.
|| e->grabbing) // Grabbing.
)
{
// Make sure entities get displayed in front of obstacle and grabbee
sortid = other->sortid + zdepth + 2;
e->sortid = sortid;
z = (int)( other->position.z + 2 );
}
else
{
//if ( e->model->type == TYPE_PLAYER ) debug_printf("zdepth: %f",zdepth);
// Entity should always display in front of the obstacle
sortid = other->sortid + zdepth + 1;
e->sortid = sortid;
z = (int)( other->position.z + 1 );
}
}
// In most cases we want any spawned entity to
// default in front of owner.
if(e->owner)
{
// If this entity is not an exception to the rule,
// move its display order in front of owner.
if (!(self->modeldata.aimove & AIMOVE1_STAR))
{
sortid = e->owner->sortid + 1;
}
}
if(e->modeldata.setlayer)
{
z = HOLE_Z + e->modeldata.setlayer; // Setlayer takes precedence
}
@DCurrent I am not explaining it right i don't want you to be able to walk though the other player so when you walk into them i want it to be like you get stopped by a wall so they are solid but right now you can walk right though them to the other side.
View attachment 11158View attachment 11157
/*
* Keep entities caller can damage from passing
* within 20px of the caller on the X axis.
*/
void dc_maintain_spacing(float min_distance)
{
int i = 0;
int entity_count = 0;
int can_damage = 0;
int entity_type = 0;
void acting_entity = NULL();
void target_entity = NULL();
float acting_x = 0;
float target_x = 0;
float diff_x = 0;
float push_dir = 0;
// Get the entity that called function.
acting_entity = getlocalvar("self");
// Get X position and candamage list for acting entity.
acting_x = getentityproperty(acting_entity, "x");
can_damage = getentityproperty(acting_entity, "candamage");
// Get total active entities.
entity_count = openborvariant("count_entities");
for (i = 0; i < entity_count; i++)
{
target_entity = getentity(i);
// Safety check: Entity must exist.
if (!getentityproperty(target_entity, "exists"))
{
continue;
}
// Get entity type.
entity_type = getentityproperty(target_entity, "type");
// Skip obstacles or self.
if (entity_type == openborconstant("TYPE_OBSTACLE") || target_entity == acting_entity)
{
continue;
}
// Skip entities we cannot damage.
if (!(entity_type & can_damage))
{
continue;
}
// Get target X.
target_x = getentityproperty(target_entity, "x");
// Calculate difference.
diff_x = target_x - acting_x;
// If absolute distance is less than minimum, push target out.
if (fabs(diff_x) < min_distance)
{
// Direction to push: if target is to the right, push right, else push left.
push_dir = (diff_x >= 0) ? 1 : -1;
// Move target to maintain spacing.
changeentityproperty(target_entity, "x", acting_x + (push_dir * min_distance));
}
}
}