Jump to content


Photo

Finding positions (platformer questions)


  • Please log in to reply
7 replies to this topic

#1 Joh

Joh

    GMC Member

  • GMC Member
  • 234 posts
  • Version:GM8

Posted 30 September 2011 - 11:38 PM

Hi im making a platformer and i have a couple questions.

I would like to summon a volcano at Mouse_x but I dont want flying a volcano, it would have t be created at the mouse_x but with a variable Y which would be the Y of the first floor block from the sky.
I thought of dropping the volcano (invisible) from y=0 and make it visible when it contacts with block, but that seems not very good.

I also want to teleport
pretty easy stuff, but the sprite of the teleported could get stuck in walls & floor, how can i prevent that? position_free(mouse_x,mouse_y) would only check for a specific point, the sprite is 64x64 how to check for a quare of freeness?


jumping through floor
i herd of a make floor not solid while you want to pass through, but that would also affect other objects that might want the floor the be solid at that instant... any other way?

thank you

Edited by Joh, 03 October 2011 - 10:06 PM.

  • 0

#2 Hazard94

Hazard94

    GMC Member

  • GMC Member
  • 56 posts
  • Version:GM8

Posted 02 October 2011 - 06:17 PM

Im not sure if this is the best way, but you can try this:

// volcano create event
do
{
  y+=1
}
until (instance_place(x,y+1,obj_floor)

This makes a loop that will make the volcano go down until it hits an obj_floor. Or whatever it is called

Edited by Hazard94, 02 October 2011 - 06:18 PM.

  • 0

#3 mads2194

mads2194

    GMC Member

  • GMC Member
  • 368 posts
  • Version:Unknown

Posted 02 October 2011 - 07:03 PM

Im not sure if this is the best way, but you can try this:

// volcano create event
do
{
  y+=1
}
until (instance_place(x,y+1,obj_floor)

This makes a loop that will make the volcano go down until it hits an obj_floor. Or whatever it is called


I`d much rather use this code, because in your code the volcano object will go down by 1 pixel even if there is a floor at that position.

while(! place_meeting(x,y+1,obj_floor))
    y+=1;

Edit:

jumping through floor


If you are using solid(which is not very recommended, since it causes a lot of problems) try something like this, in the collision event with the platform
if(y>other.y) other.solid=0
else other.solid=1

Edited by mads2194, 02 October 2011 - 07:08 PM.

  • 0

#4 Hazard94

Hazard94

    GMC Member

  • GMC Member
  • 56 posts
  • Version:GM8

Posted 02 October 2011 - 08:55 PM

// volcano create event
do
{
  y+=1
}
until (instance_place(x,y+1,obj_floor)

I`d much rather use this code, because in your code the volcano object will go down by 1 pixel even if there is a floor at that position.
while(! place_meeting(x,y+1,obj_floor))
    y+=1;


I believe mines will work ok too. It will go down until there is a collision at x,y+1 with obj_floor. So it will not go down anymore.

Anyway, use mads2194's code. It's shorter and i like it better :P

Edited by Hazard94, 02 October 2011 - 08:55 PM.

  • 0

#5 IceMetalPunk

IceMetalPunk

    InfiniteIMPerfection

  • Retired Staff
  • 9314 posts
  • Version:Unknown

Posted 02 October 2011 - 09:04 PM


// volcano create event
do
{
  y+=1
}
until (instance_place(x,y+1,obj_floor)

I`d much rather use this code, because in your code the volcano object will go down by 1 pixel even if there is a floor at that position.
while(! place_meeting(x,y+1,obj_floor))
    y+=1;


I believe mines will work ok too. It will go down until there is a collision at x,y+1 with obj_floor. So it will not go down anymore.

Anyway, use mads2194's code. It's shorter and i like it better :P

No, mads is correct. Your code will move down at least 1 px before even checking instance_place(...) (which, by the way, should be place_meeting(...) for a boolean result, though in most cases that won't matter). So if (x, y) has a collision, the result will still be (x, y+1), which is incorrect.

-IMP
  • 1

#6 Hazard94

Hazard94

    GMC Member

  • GMC Member
  • 56 posts
  • Version:GM8

Posted 03 October 2011 - 02:12 PM



// volcano create event
do
{
  y+=1
}
until (instance_place(x,y+1,obj_floor)

I`d much rather use this code, because in your code the volcano object will go down by 1 pixel even if there is a floor at that position.
while(! place_meeting(x,y+1,obj_floor))
    y+=1;


I believe mines will work ok too. It will go down until there is a collision at x,y+1 with obj_floor. So it will not go down anymore.

Anyway, use mads2194's code. It's shorter and i like it better :P

No, mads is correct. Your code will move down at least 1 px before even checking instance_place(...) (which, by the way, should be place_meeting(...) for a boolean result, though in most cases that won't matter). So if (x, y) has a collision, the result will still be (x, y+1), which is incorrect.

-IMP


Oh yes, you are right. I understand, thank you
  • 0

#7 Joh

Joh

    GMC Member

  • GMC Member
  • 234 posts
  • Version:GM8

Posted 03 October 2011 - 10:05 PM

wow, quite logical -_- should of thought of that...
thanks!
as for the jump through floor i found a way, impressed with how everything is.
  • 0

#8 Sinaz

Sinaz

    MCP Killer

  • Retired Staff
  • 2751 posts
  • Version:GM8

Posted 03 October 2011 - 10:45 PM

I would like to summon a volcano at Mouse_x but I dont want flying a volcano, it would have t be created at the mouse_x but with a variable Y which would be the Y of the first floor block from the sky.
I thought of dropping the volcano (invisible) from y=0 and make it visible when it contacts with block, but that seems not very good.

For this question, I just wanted to point out the function:

move_contact_solid(dir,maxdist) Moves the instance in the direction until a contact position with a solid object is reached. If there is no collision at the current position, the instance is placed just before a collision occurs. If there already is a collision the instance is not moved. You can specify the maximal distance to move (use a negative number for an arbitrary distance).


You can literally spawn the volcano in the sky, and use
move_contact_solid( 270, -1 );

This would assume that your floors will be the only solid obstacles.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users