A simple mob
A simple mob
I need a simple mob for a mini game I am making. I am wondering if it is better to use an existing mob api for this or write a new one.
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.
I know very little about mobs so any advice would be appreciated.
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.
I know very little about mobs so any advice would be appreciated.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!
A list of my mods can be found here
A list of my mods can be found here
Re: A simple mob
For simplicity you could use the mods redo api but if the mob in question does nothing but follow the player then this code may be simple to implement, it spawns a cube that follows player.
Code: Select all
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,
})
Re: A simple mob
Wow. Thanks!
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!
A list of my mods can be found here
A list of my mods can be found here
- kaadmy
- Member
- Posts: 706
- Joined: Thu Aug 27, 2015 23:07
- GitHub: kaadmy
- IRC: KaadmY
- In-game: KaadmY kaadmy NeD
Re: A simple mob
Ah, Slimes from Terasology?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.
Re: A simple mob
It is pacman. I should have it done in the next couple days. I am going to add more games to myboardgames modpack soon.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!
A list of my mods can be found here
A list of my mods can be found here
Re: A simple mob
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.
Anyway, even if the game turns out different than pacman, it still sounds like fun.
Re: A simple mob
I made it look the same as the old pacman but removed a couple blocks from the ghost spawn area.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.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!
A list of my mods can be found here
A list of my mods can be found here
- Gaming Association
- Member
- Posts: 62
- Joined: Tue Aug 18, 2015 01:52
- GitHub: Gerold55
- In-game: Gerold55
Re: A simple mob
You will have to wait till it is released to see.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!
A list of my mods can be found here
A list of my mods can be found here
- Christian9
- Member
- Posts: 338
- Joined: Fri Sep 19, 2014 20:29
- In-game: Christian9
- Location: Hell Creek
Re: A simple mob
I could do that quickly.give me 3 days and I can get you something just like thatDon 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.
Re: A simple mob
Pacmine is done already. It is in myarcade. The link is in my signature.Christian9 wrote:I could do that quickly.give me 3 days and I can get you something just like thatDon 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.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!
A list of my mods can be found here
A list of my mods can be found here
Who is online
Users browsing this forum: No registered users and 12 guests