iscolliding does not work??[SOLVED]

Started by spook1, Tue 04/04/2006 21:06:16

Previous topic - Next topic

spook1

In my game I use the following code:

Code: ags

function crash(){
 if (cCar.IsCollidingWithChar(cHole1) == 1)Ã,  Ã,  { 
		Display("You drove in an hole"); 
 }
}


The player is steering a car on a road (road passes by, car moves left and right). A cHole character comes from top to bottom, and moves under the cCar.
No collision is detected though?

Any suggestions??

RickJ

In the character editor there is a check box named "Solid".  You may need to check this box for both characters.  I don't if this helps or not?

Khris

Try this:
Code: ags
 if (AreThingsOverlapping(cCar.ID, cHole1.ID)) {
Ã,  Display("...");
}


Character.IsCollidingWithChar checks for baselines only.
And remember that this check has to be performed continuously, I guess your crash() function gets called within the rep_ex?

spook1

Thanks for helping.
The baselinecheck is alright with me. The characters are both set to solid.

Am I missing something about the ID?

I have characters called by their scriptoname cCar and cHole1.

I get no collision event, and the Hole moves all the way underneath the car and comes out at the bottom to move on to y = 2000 (way beyond my window bottom line, so I guess the bottomline of the car is crossed big time)

Khris

From the manual:

QuoteAreThingsOverlapping(int thing1, int thing2)

Checks whether two characters or objects are overlapping each other on screen. This simply carries out a quick rectangular check on the two things to decide - so if they have large transparent regions around the edges, it may seem to be overlapping too soon.
THING1 and THING2 can either be a CHARID, or can be an object number PLUS 1000. So for example, passing EGO as THING1, and 1004 as THING2, will compare the character EGO with Object 4 in the current room.

Thus the parameters need to be the IDs of the Characters.

And, again: Where/When do you call your crash() function?

spook1

#5
crash function is called in rep exec. section

Both are characters areactually called in the following way:

Code: ags

function botsing(){
 if (cBb11.IsCollidingWithChar(cKuil1) == 1)Ã,  Ã,  { 
		Display("Je bent in een gat gereden"); 
 }
}


Also tried:
Code: ags

function botsing(){
 if (character[BB11].IsCollidingWithChar(cKuil1) == 1)Ã,  Ã,  { 
		Display("Je bent in een gat gereden"); 
 }
}


both do not generate a collision...

Also I tested:
Code: ags

function botsing(){
 //if (cBb11.IsCollidingWithChar(cKuil1) == 1)    { 
 if (AreThingsOverlapping(BB11, KUIL1)) {
		Display("Je bent in een gat gereden"); 
 }
}


This does not function either.
If I replace the KUIL1 by EGO, the event does fire though (why??)

Additionaly I can mention that BB11 is the player character is this screen.
I start by

Code: ags

character[BB11].SetAsPlayer(); //beetje ouderwetse definitie


In player enters screen

Does this shine any additional light on the issue??

Khris

I'm not sure if
if (AreThingsOverlapping(BB11, KUIL1))
will work, use
if (AreThingsOverlapping(cBb11.ID, cKuil1.ID))
instead.

As it says right in the manual excerpt I've quoted, the two parameters need to be CHARIDs, not old-style script names.

Character.ID returns the index of the character[] array element holding the char, so cEgo == character[cEgo.ID]

Ashen

#7
The 'old style script names' ARE character IDs - by default character[EGO] is the same as character[0] (is the same as cEgo, obviously, but that's not the point), so it should work with if (AreThingsOverlapping(BB11, KUIL1)), provided those are the right characters.

However, that's equivilant to if (AreThingsOverlapping(BB11, KUIL1)==1), and if you read the manual:
Quote from: AreThingsOverlapping
Returns 0 if they are not overlapping, or the overlapping amount if they are. This amount is an arbitrary scale, but 1 means they are just about touching, all the way up to higher numbers for more overlappingness.

So maybe use if (AreThingsOverlapping(BB11, KUIL1) > 1) instead, to allow any amount of overlap. However I can't see why you're using IsColliding AND AreOverlapping in that last example - sure one or the other would be better?

I know what you're thinking ... Don't think that.

spook1

Thanks for your ongoing interest in my problem.

I have tried the suggestions, but it does not work :-((

I did try both functions as an experiment, indeed the AreThingsOverlapping options is preferable.

I thought of an interesting feature though: in my little game I use :

cBb11.ChangeView(SelectTankView());

where SelectTankView is a functions that figures out the correct view (moving right, left, forward, on the middle, right, or left side of the road.

Moving staright forward on the left side of the road is represented by a vehicle pointing diagonally to the right (due to the perspective).

Can this have any consequences for the functions??

Khris

Ashen: Without testing it, I'm pretty (absolutely) sure that if (AreThingsOverlapping(...)) is indeed equivalent to if (AreThingsOverlapping(...) != 0), not ==1). So my suggestion should actually work perfectly, even though I didn't read the bit you've quoted.

Everything besides 0 will evaluate to true in an if-condition.

And spook1 didn't use both tests; if (cBb11.IsCollidingWithChar(cKuil1) == 1)Ã,  Ã,  { is commented out in the last snippet.

Ashen

And that's why I should never post with a head full of cold ....

KhrisMUC's right, it's actually equal to '!= 0', not '== 1' - please ignore everything after the first paragraph in my previous post as delerious ravings. Not sure how I missed the commented out line, though.

Sorry I can't shed any light on the actual problem, though. One thing - when you set BB11 as the player character, what happens to the previous player (I'd guess EGO)? (Trying to figure out why replacing KUIL1 with EGO works.)
I know what you're thinking ... Don't think that.

Gilbert

Try not to set tem as solid, it might be possible that they won't collide if they're solid.

spook1

Finally, after many debug parameters and test I found it.

I am very sorry to tell that you guys could not have figured it out: it was my coding error  :-[

I apologise for having tkane so much of your time, for a stupid scripting error. :-[ :-[

I fired the cKuil1 character at certain random times.
at timer = 200 cKuil1 walk to 150, 150.

Once the Kuil1 was fired, I set the cKuil.x to -1000
If fire-event had passed I reset the timer (and therefore also the cKuil.x coordinate, to wait for the next fire-event.)

I added a (cKuil1.Moving != true) restriction => now all functions work great!!

if you're interested:

Code: ags

function start_kuil(int aan){
  
  if (aan == -1) { cKuil1.x = 1000;}
  else if (aan == 1){
    
    SetFlashlightDarkness (GetFlashlightDarkness() -10); // beetje donkerder maken
    
    cKuil1.x = 163;
    cKuil1.y =  39;
    
    cKuil1.Walk(Random(300), 340, eNoBlock, eAnywhere);
    }

		
}
//###################################################################################################################################################

//###################################################################################################################################################
//***  Tikker  ***
//----------------------------------------------------------------------------------------------------------------------------------------------------
//This function telt af en kijkt of het al tijd is voor een event. Maakt gebruiker van variabele tikteller.
//----------------------------------------------------------------------------------------------------------------------------------------------------
function tikker(){
  
  tikteller = tikteller + 1;
  if ((tikteller > KUILENTIJD ) && (cKuil1.Moving != true)) {
		tikteller = 0;
		
		start_kuil(1);
  }
  else if (cKuil1.Moving != true) {start_kuil(-1);}






The kuil remained visible though, as it was first finisheing the walk() command

SMF spam blocked by CleanTalk