- local dir = vector.direction(pos,pos2)
- dir.y = 0
-
- --eliminate mob being stuck in corners
- if dir.x == 0 and dir.z == 0 then
- dir = vector.new(math.random(-1,1)*math.random(),0,math.random(-1,1)*math.random())
- end
-
- local velocity = vector.multiply(dir,1.1)
-
- local vel1 = vector.multiply(velocity, -1)
- local vel2 = velocity
- self.object:add_velocity(vel1)
-
- if object:is_player() then
- object:add_player_velocity(vel2)
- else
- object:add_velocity(vel2)
+ local object_collisionbox = object:get_properties().collisionbox
+
+ pos2.y = pos2.y + object_collisionbox[2]
+
+ local object_collision_boundary = object_collisionbox[4]
+
+
+ --this is checking the difference of the object collided with's possision
+ --if positive top of other object is inside (y axis) of current object
+ local y_base_diff = (pos2.y + object_collisionbox[5]) - pos.y
+
+ local y_top_diff = (pos.y + collisionbox[5]) - pos2.y
+
+
+ local distance = vector.distance(vector.new(pos.x,0,pos.z),vector.new(pos2.x,0,pos2.z))
+
+ if distance <= collision_boundary + object_collision_boundary and y_base_diff >= 0 and y_top_diff >= 0 then
+
+ local dir = vector.direction(pos,pos2)
+ dir.y = 0
+
+ --eliminate mob being stuck in corners
+ if dir.x == 0 and dir.z == 0 then
+ dir = vector.new(math.random(-1,1)*math.random(),0,math.random(-1,1)*math.random())
+ end
+
+ local velocity = vector.multiply(dir,1.1)
+
+ local vel1 = vector.multiply(velocity, -1)
+ local vel2 = velocity
+ self.object:add_velocity(vel1)
+
+ if object:is_player() then
+ object:add_player_velocity(vel2)
+ else
+ object:add_velocity(vel2)
+ end