# olivebates

Member Since 13 May 2008
Offline Last Active May 20 2013 03:26 PM

### In Topic: How Do I Calculate Where The Player Will Land?

20 May 2013 - 03:18 PM

Alright, I've edited it a little bit, so it looks like this now:

```//This script calculates where the player will land and makes a block
//scrGenMakeBlock(objectCreate, objectAvoid, minBlocks, maxBlocks, pillarSize, checkForPlayer?)

//Variable setup
wallobject=argument0;
spr=object_get_sprite(wallobject);
ox=sprite_get_xoffset(spr);
w=sprite_get_width(spr);
oy=sprite_get_yoffset(spr);
h=sprite_get_height(spr);

//Create the block
for (ii = argument2; ii <= argument3; ii += 1)
{
//calculate position of block
dy=round((y+dy)/h)*h-y;

t=sqr(gravity*.5+vspeed)+2*gravity*dy;
if t<0
{
continue;
}

tx=((sqrt(t)-vspeed)/gravity-.5)*hspeed
ty=y+dy;
tx=round((tx)/w)*w;

//Save the player variables
pxscl=image_xscale;
image_xscale=1;
pyscl=image_yscale;
image_yscale=1;
pang=image_angle;
image_angle=0;

//Create the block
//check for objectAvoid, and if too close
if (!place_meeting(tx, ty, argument1))
{
//create all the blocks in the pillar
for (ii = 0; ii < argument4; ii += 1)
{
//check if each individual block is not overlapping objectAvoid
if (!place_meeting(tx, ty +(ii*32), argument1))
{
//create the block
t = instance_create(tx, ty +(ii*32), wallobject);

//destroy if player is there
if (argument5)
with (t)
if place_meeting(x,y,other)
{
instance_destroy();
with (other)
continue;
}
}
}
//end
break;
}
}

//reset plater sprites
image_xscale=pxscl;
image_yscale=pyscl;
image_angle=pang;
```

So Now I should just be able to set minBlocks to -5, and maxBlocks to 5, and then it should find the highest block that the player will land on. Though it often creates the block, so the player hits it from the side. Is there a way to make it, so it will find the highest block that the player can land on?

### In Topic: How Do I Calculate Where The Player Will Land?

20 May 2013 - 02:03 PM

Works much better, thanks <3

I tried switching this part at the end

```with t
if place_meeting(x,y,other)
instance_destroy(); ```

out with

```if (place_meeting(tx, ty, object_index))
exit;
```

and moved it up to right before it creates the block, but it doesn't want to check for if the player is there. Why is this?

### In Topic: How Do I Calculate Where The Player Will Land?

18 May 2013 - 04:03 PM

Hmm, I suppose you are quite right. There are a few times where it misses, but it's accurate enough.

I have another thing tho, because when I want to create a wall, that blocks the player (adding the tx+=(sprite_get_width(mask_index)>>1)*sign(hspeed); line),  I am unable to create them above the player, as I cannot set the number_of_blocks to a negative number (due to the square root). I would however like to. Is there a way, where we can turn the calculation into the negatives?

Also, if we could turn the calculation 90¤, and instead of saying number_of_blocks to the bottom, saying number_of_blocks to the right? So it checks horisontially, instead of vertically? This would be very helpfull.

Sorry if this is asking for too much~.

### In Topic: Why Do These Two Expressions Work Differently?

11 May 2013 - 05:46 PM

Thanks man, that clears it up!

### In Topic: How Do I Calculate Where The Player Will Land?

11 May 2013 - 04:10 PM

Edit

It still seems to create them higher than the player will land in it, he only lands on it ½ the time. Though the allignment is right