A simple mob

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

A simple mob

by Don » Mon Oct 19, 2015 01:14

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.
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
 

User avatar
TenPlus1
Member
 
Posts: 1874
Joined: Mon Jul 29, 2013 13:38
GitHub: tenplus1

Re: A simple mob

by TenPlus1 » Mon Oct 19, 2015 19:57

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.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
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,
})
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: A simple mob

by Don » Mon Oct 19, 2015 20:29

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
 

User avatar
kaadmy
Member
 
Posts: 627
Joined: Thu Aug 27, 2015 23:07
GitHub: kaadmy
IRC: KaadmY
In-game: KaadmY kaadmy NeD

Re: A simple mob

by kaadmy » Mon Oct 19, 2015 23:45

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.

Ah, Slimes from Terasology?
Never paint white stripes on roads near Zebra crossings.
 

User avatar
MineYoshi
Member
 
Posts: 4267
Joined: Wed Jul 08, 2015 13:20
GitHub: MineYosh
IRC: MineYoshi
In-game: Kirby_Retro

Re: A simple mob

by MineYoshi » Tue Oct 20, 2015 15:05

NO!
i think is pacman!
People talk about freedom of speech, so i'll say that God exists.
Open your eyes!! See The big unicorn conspiracy.!! :D The government has been lying to us about unicorns!!
"I've learned there are three things you don't discuss with people: religion, politics and the Great Pumpkin" - Linus Van Pelt
I'm the Officially 1st ABJist in the world ( ͡° ͜ʖ ͡°)
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: A simple mob

by Don » Tue Oct 20, 2015 15:45

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
 

User avatar
Ferk
Member
 
Posts: 330
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: A simple mob

by Ferk » Tue Oct 20, 2015 16:44

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.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: A simple mob

by Don » Tue Oct 20, 2015 17:38

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.

I made it look the same as the old pacman but removed a couple blocks from the ghost spawn area.
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
 

User avatar
Gaming Association
Member
 
Posts: 62
Joined: Tue Aug 18, 2015 01:52
GitHub: Gerold55
In-game: Gerold55

Re: A simple mob

by Gaming Association » Sat Oct 31, 2015 18:25

so ull b able 2 play it like the original pacman arcade game?
Gaming Association
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: A simple mob

by Don » Sat Oct 31, 2015 19:00

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
 

User avatar
Christian9
Member
 
Posts: 273
Joined: Fri Sep 19, 2014 20:29
In-game: Christian9

Re: A simple mob

by Christian9 » Sun Nov 22, 2015 05:56

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
 

User avatar
Don
Member
 
Posts: 1641
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: A simple mob

by Don » Sun Nov 22, 2015 12:55

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

Pacmine is done already. It is in myarcade. The link is in my signature.
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
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron