local gravity = -10
minetest.register_entity("test:testy", {
hp_max = 1,
physical = true,
collide_with_objects = true,
visual = "cube",
visual_size = {x = 0.5, y = 0.5},
textures = {"sides.png", "sides.png", "sides.png", "sides.png", "front.png", "sides.png"},
velocity = {x=math.random(-1,1), y=0, z=math.random(-1,1)},
collisionbox = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
weight = 5, -- ??
is_visible = true,
automatic_rotate = true,
automatic_face_movement_dir = -90, -- set yaw direction in degrees, false to disable
stepheight = 1.1,
makes_footstep_sound = true,
floats = 1,
view_range = 10,
speed = 1,
jump_height = 5,
set_velocity = function(self, v)
if not v then v = 0 end
local yaw = self.object:getyaw()
self.object:setvelocity({x=math.sin(yaw) * -v, y=self.object:getvelocity().y, z=math.cos(yaw) * v})
end,
on_step = function(self, dtime)
-- every 1 second
self.timer = (self.timer or 0) + dtime
if self.timer < 1 then return end
self.timer = 0
-- make sure object floats (or not) when in water
if minetest.get_item_group(minetest.get_node(self.object:getpos()).name, "water") ~= 0 then
if self.floats == 1 then
self.object:setacceleration({x = self.object:getacceleration().x, y = 1.5, z = self.object:getacceleration().z})
end
else
self.object:setacceleration({x = self.object:getacceleration().x, y = gravity, z = self.object:getacceleration().z})
end
local s, p, dist, nod
-- find player to follow
for _,player in pairs(minetest.get_connected_players()) do
s = self.object:getpos()
p = player:getpos()
-- find distance
dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5
if dist < self.view_range then
local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z}
local yaw = (math.atan(vec.z/vec.x)+math.pi/2)
if p.x > s.x then
yaw = yaw + math.pi
end
-- face player
self.object:setyaw(yaw)
-- find direction and show node facing
self.direction = {x = math.sin(yaw)*-1, y = 0, z = math.cos(yaw)}
nod = minetest.get_node_or_nil({x=s.x + self.direction.x,y=s.y+1,z=s.z + self.direction.z})
print ("facing node", nod.name, dist)
-- more than 2 nodes ahead then follow, otherwise stop
if dist > 2 then
if self.jump_height > 0 and self.object:getvelocity().y == 0 then
local v = self.object:getvelocity()
v.y = self.jump_height
self.object:setvelocity(v)
end
self.set_velocity(self, self.speed)
else
self.set_velocity(self, 0)
end
-- break look after player found
break
end
end
end,
})
Don wrote:The mob only needs to chase a player. There is no animation, punch or attack. I don't even want the player to be able to hit the mob.
Ferk wrote:I still think it would make more sense if the ghosts followed a more "square" pattern. You won't be able to use a standard pacman map if the ghosts spawn all in the center and follow this algorithm, or else they will always go in the same direction without spreading out. So you'll need them to spawn in the corners.
Anyway, even if the game turns out different than pacman, it still sounds like fun.
Don wrote: mob only needs to chase a player. There is no animation, punch or attack. I don't even want the player to be able to hit the mob.
Christian9 wrote:Don wrote: mob only needs to chase a player. There is no animation, punch or attack. I don't even want the player to be able to hit the mob.
I could do that quickly.give me 3 days and I can get you something just like that
Users browsing this forum: No registered users and 3 guests