Hello.
Context of problem:
The player is flying across the screen from left to right.
coins and fruit drift the other way.
When the player intercepts a coin or fruit, it disappears and he gets some points.
The Problem:
This was working fine, until I changed the player's view.
Now he can only pick up the coins. The fruit is untouchable.
The coins are characters, the fruit are objects. (Because learning.)
Any idea what's astray?
*Edit*
I tried changing the player view back to the original place-holder graphic. He still can't intercept the fruit. So I must have changed something else. I'll keep fiddling with it- but I guess my question now is, what's wrong with this:
function room_RepExec()
{
if (cCharacter.IsCollidingWithObject(object[0])){
GiveScore(400);
object[0].Visible = false;
}
....}
Regards
MDC
You're only checking for collisions with the very first object in the room. Since this used to work, did you change the rep_exec code?
You have to iterate through all room objects:
function room_RepExec()
{
int i;
while (i < Room.ObjectCount) {
if (cCharacter.IsCollidingWithObject(object[i])) {
GiveScore(400);
object[i].Visible = false;
}
i++;
}
}
Thank you for your reply.
I still have not fixed the problem, maybe because I don't understand the solution you offered.
Do you mean I use the
int i;
while (i < Room.ObjectCount)...
code instead of
if (cCharacter.IsCollidingWithObject(object[0])){
GiveScore(400);
object[0].Visible = false;
}
if (cCharacter.IsCollidingWithObject(object[1])){
GiveScore(400);
object[1].Visible = false;
}
if (cCharacter.IsCollidingWithObject(object[2])){
GiveScore...
I tried both, but neither worked.
Should I replace "i" in the code you offered with the number of objects in the room?
(that didn't work either.)
I don't know the meaning of ++i;
Yes, that's what the code does.
int i;
while (i < 3) {
Display("loop %d", i);
i++;
}
will produce the following three messages, "loop 0", "loop 1", "loop 2".
The i++ is short for i = i + 1. Without it, i will remain 0 and AGS will crash giving a 150,000 loops message. The while keyword doesn't increase anything, it'll keep calling the code inside { and } as long as the condition is true.
There's really no need to change my code, if you replace i with the number of objects, you'll get an error because if there are 5 objects, they're object[0] to object[4], and object[5] is undefined.
But the code does what it's supposed to anyway.
According to the manual, the cCharacter.IsCollidingWithObject command checks the character's feet against the object area. Does the collision never happen AT ALL, even if you steer the character into the fruit with their "feet", i.e. the bottom center of the sprite?
No luck. cCharacter is just drifting through the fruit objects like they weren't there. He is colliding with the coins though, which are characters.
I'll leave it for now and work on some other problems.
I suspect that that the correct solution is to delete the room, and rebuild it from scratch.
Thank you for your efforts.
You say that it only works with characters? Make the fruit be a character! It's so simple!
If AGS does not run a collide code,when player collides with an object, it is usually because the collide is not being detected by AGS, as per Khris.
You may like to try the PP Collision module if you can't resolve this issue, it detects collision better by drawing a retangle around the object / character rather than just at its feet.
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=26307
Make sure you repeat for all Objects / Chars
Example of PPCollision code that I have used on various occasions (in RepExec):
function repeatedly_execute()
{
if (PPColliding.CWithO (cPlayer, ofruit))
// C with O = Character collides with Object. cPlayer and ofruit: change as required.
{
YOUR CODE HERE
}
}
// Repeat for all collisions.
This is an alternative to the usual collide code.
Food for thought
:-D
YES!!
It worked!
Pixel-perfect collision did the trick.
My next question is:
Where on my body should I put my big blue cup tattoo?
(Thanks all.)
:X