Physics Snap to Grid

R

reecehunter

Guest
Hey i've been working on a little Terraria-like game and I was doing fine with snapping blocks to a grid when the player places them, but when i created an arrow object (which uses physics), i also had to make the blocks use physics, which makes them not snap to the grid anymore. I can't find a way to get around this or fix it.

block create event:
Code:
move_snap(16,16);
arrow create
Code:
dir = point_direction(x,y,mouse_x,mouse_y);
physics_apply_impulse(x,y,lengthdir_x(obj_bow.force,dir),lengthdir_y(obj_bow.force,dir));

hit = false;
arrow step event:
Code:
if(!hit){
    phy_rotation = -point_direction(x,y,x+phy_speed_x,y+phy_speed_y);
    phy_angular_velocity = 1;
}
arrow collision event:
Code:
//Collision
hit = true;
 

FrostyCat

Member
This is just a trivial rehash of the math underneath move_snap().
Code:
phy_position_x = (phy_position_x div 16) * 16;
phy_position_y = (phy_position_y div 16) * 16;
 
Top