Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075929 Posts in 44152 Topics- by 36119 Members - Latest Member: Royalhandstudios

December 29, 2014, 04:03:28 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Collision Rectangle not Working(?)
Pages: [1]
Print
Author Topic: Collision Rectangle not Working(?)  (Read 1401 times)
jddg5wa
Level 1
*



View Profile
« on: October 03, 2013, 04:06:29 AM »

Now I don't know if the collision rectangle isn't working or there is something else causing it to not do what is expected. I know I tend to make code errors but it's such a simple code that I can't figure out why it's not doing anything. I've gone over it and other things to check and still nothing. Looking for some suggestions of what could be wrong at this point; since I'm totally stumped. Thanks.

Code:
//Abduction Trigger
if collision_rectangle(alien_ship.x-72,alien_ship.y+42,alien_ship.x+72,alien_ship.y+219,cow,true,false)
    {
        global.abduct=1
    }
    
else
    {
        global.abduct=0
    }



The "problem" is that global.abduct stays at 0 even when object "cow" is in the supposed area.
« Last Edit: October 03, 2013, 04:41:58 AM by jddg5wa » Logged

\\\"Around here, however, we don\\\'t look back for very long. We keep moving forward, opening new doors, and doing new things, because we\\\'re curious and curiosity keeps leading us down new paths.\\\"      - Walt Disney
rundown
Level 5
*****



View Profile WWW Email
« Reply #1 on: October 03, 2013, 04:39:20 AM »

Now I don't know if the collision rectangle isn't working or there is something else causing it to not do what is expected. I know I tend to make code errors but it's such a simple code that I can't figure out why it's not doing anything. I've gone over it and other things to check and still nothing. Looking for some suggestions of what could be wrong at this point; since I'm totally stumped. Thanks.

Code:
//Abduction Trigger
if (collision_rectangle(alien_ship.x-72,alien_ship.y+42,alien_ship.x+72,alien_ship.y+219,cow,true,false))
    {
        global.abduct=1
    }
    
else
    {
        global.abduct=0
    }



The "problem" is that global.abduct stays at 0 even when object "cow" is in the supposed area.

I'm not sure you are allowed to make spaces between if and else.
In some of the coding I use it isn't allowed.

if
{
}
else
{
}

not

if
{
}

else
{
}
Logged

jddg5wa
Level 1
*



View Profile
« Reply #2 on: October 03, 2013, 04:47:58 AM »

I'm not sure you are allowed to make spaces between if and else.
In some of the coding I use it isn't allowed.

Hmm, never had that problem before. Removed the space but it didn't effect anything.'

Has the cow's sprite got precise collision checked?

@rundown spaces don't matter
Yes

On a sort of related, but not, note, does anyone happen to know how to achieve the same effect using a collision event with a collision rectangle in a step event? Stopping movement in a collision event seems to actually stop movement. Where as detecting collision in the step event with a collision rectangle doesn't do the same thing.  
Logged

\\\"Around here, however, we don\\\'t look back for very long. We keep moving forward, opening new doors, and doing new things, because we\\\'re curious and curiosity keeps leading us down new paths.\\\"      - Walt Disney
mokesmoe
Level 10
*****



View Profile WWW Email
« Reply #3 on: October 03, 2013, 04:30:49 PM »

I notice your cow object is just named "cow". Make sure you don't also have it's sprite named "cow" or that will mess it up.

Collision is step events should work the same except it won't use gamemaker's built-in "solid" collision. If you were using solid collision just send your object back to xprevious and yprevious and work from there.
Logged
jddg5wa
Level 1
*



View Profile
« Reply #4 on: October 03, 2013, 04:47:12 PM »

I notice your cow object is just named "cow". Make sure you don't also have it's sprite named "cow" or that will mess it up.

Collision is step events should work the same except it won't use gamemaker's built-in "solid" collision. If you were using solid collision just send your object back to xprevious and yprevious and work from there.

Yea I've made sure, the cow sprite is named cow_sp. I've gone over a lot of things but nothing has made a difference so far. Then again I could have missed something. It's such a simple script that it doesn't make sense to it not working.

With the collision I had to resort back to using the collision event. I couldn't get xprevious and yprevious, or a good alternative, working in the step event so my object just fell through platforms.
Logged

\\\"Around here, however, we don\\\'t look back for very long. We keep moving forward, opening new doors, and doing new things, because we\\\'re curious and curiosity keeps leading us down new paths.\\\"      - Walt Disney
ink.inc
Guest
« Reply #5 on: October 03, 2013, 05:30:29 PM »

for sprites i put a lowercase s in front of a capitalized sprite name
for objects i put an o, etc. etc.
Logged
jddg5wa
Level 1
*



View Profile
« Reply #6 on: October 04, 2013, 02:04:09 AM »

So... oddly the script works. I went ahead without it and worked on the script that the variable was supposed to trigger. It works and triggers the script. Still don't see a change in debug mode which doesn't make sense. I won't question it though for fear that it might stop working. Tongue
Logged

\\\"Around here, however, we don\\\'t look back for very long. We keep moving forward, opening new doors, and doing new things, because we\\\'re curious and curiosity keeps leading us down new paths.\\\"      - Walt Disney
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic