Posted: 25th May 2023 17:39
So I get perfect sliding collision for my player object, but.

My enemies that are free roaming do not get collision at all with each other even if I put them in there own sliding code.

I was thinking perhaps it is because there loaded into a array from a type?

Or perhaps it is there size being scaled permanently?

When I give them sliding collision with the world they get perfect sliding collision.

But I do not know how to give them there own collision in-between each other as there loaded as a array and the system is looking at them as the same so how can the same objects have collision with its self. I could be wrong and correct me if I am but this is what I see in my mind.

When there are two or more attacking the player they slide into each other pos and sometimes there is three or four enemies all in the same pos.


Edit<

Here is my whole function that will not detect collision for my enemies with each other.


+ Code Snippet
function FightFreeEnemys()
	
For x=0 to FreeEnemy.length

 rem Old object position
 oldx#=GetObjectX(FreeEnemy[x].id)
 oldy#=GetObjectY(FreeEnemy[x].id)
 oldz#=GetObjectZ(FreeEnemy[x].id)

SetObjectLookAt(FreeEnemy[x].id,GetObjectX(player),GetObjectY(FreeEnemy[x].id), GetObjectz(player),0)	

FreeEnemy[x].Distance=getDistance(player,FreeEnemy[x].id)
FreeEnemy[x].SelfDistance=getDistance(FreeEnemy[0].id,FreeEnemy[2].id)
 
//goblin mounted idel
if FreeEnemy[x].Distance=&gt;200 and FreeEnemy[x].Trigger=0
    PlayObjectAnimation(FreeEnemy[x].id,"",1,29,1,0.1)
    SetObjectAnimationSpeed(FreeEnemy[x].id,30)	
    SetObjectPosition(FreeEnemy[x].id,GetObjectX(FreeEnemy[x].id),GetObjectHeightMapHeight(terrain,GetObjectX(FreeEnemy[x].id),GetObjectZ(FreeEnemy[x].id)),GetObjectZ(FreeEnemy[x].id))
    FreeEnemy[x].Trigger=1
endif
//goblin mounted walk
if FreeEnemy[x].Distance=&gt;30 and FreeEnemy[x].Distance=&lt;200
    if FreeEnemy[x].Trigger=1
    PlayObjectAnimation(FreeEnemy[x].id,"",72,88,1,0.1)
    SetObjectAnimationSpeed(FreeEnemy[x].id,30)	
     FreeEnemy[x].Trigger=0
     endif
     MoveObjectLocalZ(FreeEnemy[x].id,0.7)

     SetObjectPosition(FreeEnemy[x].id,GetObjectX(FreeEnemy[x].id),GetObjectHeightMapHeight(terrain,GetObjectX(FreeEnemy[x].id),GetObjectZ(FreeEnemy[x].id)),GetObjectZ(FreeEnemy[x].id))
endif
//goblin mounted attack
if FreeEnemy[x].Distance&gt;0 and FreeEnemy[x].Distance=&lt;29
	if FreeEnemy[x].Trigger=0
    PlayObjectAnimation(FreeEnemy[x].id,"",90,154,1,0.1)
    SetObjectAnimationSpeed(FreeEnemy[x].id,40)	
     FreeEnemy[x].Trigger=1
     endif
     if  FreeEnemy[x].Distance&lt;27 then MoveObjectLocalZ(FreeEnemy[x].id,-0.3)
     SetObjectPosition(FreeEnemy[x].id,GetObjectX(FreeEnemy[x].id),GetObjectHeightMapHeight(terrain,GetObjectX(FreeEnemy[x].id),GetObjectZ(FreeEnemy[x].id)),GetObjectZ(FreeEnemy[x].id))
endif

 rem New position
 newx#=GetObjectX(FreeEnemy[x].id)
 newy#=GetObjectY(FreeEnemy[x].id)
 newz#=GetObjectZ(FreeEnemy[x].id)
 
  if ObjectSphereSlide(FreeEnemy[x].id,oldx#,oldy#,oldz#,newx#,newy#,newz#,5.1)&gt;0
  newx#=GetObjectRayCastSlideX(0)
  newy#=GetObjectRayCastSlideY(0)
  newz#=GetObjectRayCastSlideZ(0)
  SetObjectPosition(FreeEnemy[x].id,newx#,newy#,newz#)
  endif
  

next x
	
endfunction
Posted: 18th Jun 2023 16:57
I believe the problem is here:

+ Code Snippet
  if ObjectSphereSlide(FreeEnemy[x].id,oldx#,oldy#,oldz#,newx#,newy#,newz#,5.1)&gt;0
  newx#=GetObjectRayCastSlideX(0)
  newy#=GetObjectRayCastSlideY(0)
  newz#=GetObjectRayCastSlideZ(0)
  SetObjectPosition(FreeEnemy[x].id,newx#,newy#,newz#)
  endif


All the parameters of the sphere cast belong to the same npc, FreeEnemy[x]. The npc is checking for collision with itself. What you need to do is check for collision against all the other npcs.

The sphere cast code needs to look more like this (Note that the object that the sphere cast checks changed to "y")

+ Code Snippet
	for y = 0 to FreeEnemy.length 
		if ObjectSphereSlide(FreeEnemy[y].id,oldx#,oldy#,oldz#,newx#,newy#,newz#,5.1)&gt;0
			newx#=GetObjectRayCastSlideX(0)
			newy#=GetObjectRayCastSlideY(0)
			newz#=GetObjectRayCastSlideZ(0)
			SetObjectPosition(FreeEnemy[x].id,newx#,newy#,newz#)
		endif
	next y


The current code is not particularly efficient as it will do each check twice. For instance if there a 3 npcs, with FreeEnemy.length = 2
- On the first loop of x it'll check x=0 againt y=0, y=1 and y=2.
- On the second loop of x it'll check x= 1 against y=0, y=1 and y=2.
- On the third loop of x it'll check x= 2 against y=0, y=1 and y=2.

It does each check twice and also checks each npc against itself. So it's more efficient to do:

+ Code Snippet
	for y = x+1 to FreeEnemy.length 
		if ObjectSphereSlide(FreeEnemy[y].id,oldx#,oldy#,oldz#,newx#,newy#,newz#,5.1)&gt;0
			newx#=GetObjectRayCastSlideX(0)
			newy#=GetObjectRayCastSlideY(0)
			newz#=GetObjectRayCastSlideZ(0)
			SetObjectPosition(FreeEnemy[x].id,newx#,newy#,newz#)
		endif
	next y


So,
- On the first loop of x it'll check x=0 against y=1, y=2
- On the second loop of x it'll check x= 1 against y=2
- On the third loop of x it'll check x= 2 but now y=3 which is higher than the maximum value of FreeEnemy.length so this will end the loop.

Hope this makes sense.
Posted: 12th Jul 2023 6:34
29 games

Thank you for the look and help.

I have not been coding for awhile and took a break so i will test this soon and let you know.

What you said is true and Sounds right so i am sure it will work.

And When I was writing this code I was trying to wrap my head around array groups and could not figure how to include each one. What you showed looks more sound.