[ 2 posts ]  Reply to topicPost new topic 
Author Message
 [aq]
 Post subject: Collision Problem
PostPosted: Fri Dec 17, 2010 10:33 pm 
User avatar
Obey.
Member
[*]
[*]
I'm having a problem making collisions using my own script.
Mario falls through the ground when I turn on treat uninitialized variable as 0 in the global game settings so I turned it off. If I turn it off, I get an error :blank: :
Quote:
___________________________________________
ERROR in
action number 4
of Step Event
for object obj_mario:

In script col_rect:
Error in code at line 2:
if argument0 > block.bbox_left //x1
^
at position 23: Unknown variable bbox_left


I used this code for my script:
Code:
block = collision_rectangle(bbox_left,bbox_top,bbox_right,bbox_bottom,obj_solidground,1,1)
if argument0 > block.bbox_left //x1
or argument1 > block.bbox_bottom //y1
or argument2 < block.bbox_left //x2
or argument3 < block.bbox_top //y2
    return false;
else
    return true;


I use it in the step event:
Code:
if col_rect(bbox_left,bbox_bottom,bbox_right,bbox_bottom+yspeed+1,obj_solidground)//collision_rectangle(bbox_left,bbox_bottom,bbox_right,bbox_bottom+yspeed+1,obj_solidground,1,1)
    {
        topblock = collision_rectangle(bbox_left,bbox_bottom,bbox_right,bbox_bottom+yspeed+1,obj_solidground,1,1)
        if yspeed > 0 and y+sprite_height < topblock.bbox_top+1
            {
                y = topblock.bbox_top-31
                yspeed = 0
                grav = 0
                jumpnow = 0
            }
    }
else
    {
        if yspeed < -2
            grav = 0.1
        else
            grav = 0.3
    }


Is there a way to fix it?

_________________
I am your supreme leader
 
Top
Offline 
 User page at mfgg.net
 
 [zz]
 Post subject: Re: Collision Problem
PostPosted: Sat Dec 18, 2010 9:47 am 
User avatar
Member
[*]
[*]
Let's correct your scripts by steps:
1-you create a script that check if it is a collision or not with a object_solid_ground.But it is useless.Why?Because if colision__rectangle(...,obj_solidground)=-1,It doesn't have collision with this,but if colision__rectangle(...,obj_solidground)!=-1 (that the obj.id), it has a collision.So true and false result coud be made in a simpler way.
2-If you want to use this script,you need to fix the inequalities.First x1(argument0) must be >block.bbox_right.And you need to change "or" for "and",because if,for example,x2<block.bbox_left and block.bbox_top<y2<block.bbox_bottom,by logic,must have a collision.
3-This error warning is due the fact that block will be -1,because Mario doesn't collide with anything.if block isn't a obj.id,so doesn't exist block.bbox_left and the others.
4-Change "y+sprite_height < topblock.bbox_top+1" for y+sprite_height-vspeed < topblock.bbox_top+1,because it possible,with a higher vspeed, that "y+sprite_height >topblock.bbox_top+1", and Mario falls.

I didn't test theses fixes,so I don't the possible results.

 
Top
Offline 
 
 
« Previous topic | Next topic »
Display posts from previous:  Sort by  
 [ 2 posts ]  Reply to topicPost new topic 


Who is online

Users browsing this topic: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group