Use vector.from_speed_yaw

master
Ciaran Gultnieks 2014-04-04 20:41:15 +01:00
parent 38c39cb64a
commit acf43e0267
2 changed files with 5 additions and 17 deletions

View File

@ -11,6 +11,7 @@ the current git version, plus these:
* https://github.com/CiaranG/minetest/commit/45dc321b3c48f449bac5f9985db587847490d3e2
* https://github.com/CiaranG/minetest/commit/830f306d0800e1e504174799c410e75a35687f1b
* https://github.com/CiaranG/minetest/commit/294d98c3783c1c1f5abe05e509982ba535f60b46
* https://github.com/CiaranG/minetest/commit/db67b29f925a477a33ebe6d784fccab332214952
This mod provides 'people' (non player characters) that are programmable
in-game. Each NPC's Lua code runs inside a secure sandbox for that NPC only.

View File

@ -43,19 +43,6 @@ local animations = {
}
local walk_velocity = function(speed, yaw)
if speed == 0 then
return {x=0, y=0, z=0}
end
yaw = yaw + math.pi * 0.5
local x = math.cos(yaw) * speed
local z = math.sin(yaw) * speed
return {x=x, y=0, z=z}
end
--- Find the next node along a footpath
-- All positions are exact (rounded) node positions.
-- @param curpos The position of a current footpath node
@ -183,7 +170,7 @@ people.actions.follow = function(state)
end
local dir = math.random(math.pi*2)
targetpos = vector.add(targetpos, walk_velocity(2, dir))
targetpos = vector.add(targetpos, vector.from_speed_yaw(2, dir))
targetpos = vector.round(targetpos)
-- TODO find surface Y
dbg.v3(state.ent.name.." following "..state.action.name.." via "..minetest.pos_to_string(targetpos))
@ -364,10 +351,10 @@ people.actions.go = function(state)
else
-- pick a couple of nearby points and walk to them, then try again
local randomdir = math.random(math.pi * 2)
vec = walk_velocity(24, randomdir)
vec = vector.from_speed_yaw(24, randomdir)
local rpos = {x=math.floor(state.pos.x + vec.x + 0.5), y=state.pos.y, z=math.floor(state.pos.z + vec.z + 0.5)}
randomdir = math.random(math.pi * 2)
vec = walk_velocity(24, randomdir)
vec = vector.from_speed_yaw(24, randomdir)
local rpos2 = {x=math.floor(rpos.x + vec.x + 0.5), y=state.pos.y, z=math.floor(rpos.z + vec.z + 0.5)}
if not state.action.intermediate then
state.action.intermediate = {}
@ -634,7 +621,7 @@ minetest.register_entity("people:person" ,{
if state.setpos then
self.object:setpos(state.setpos)
end
local setvel = walk_velocity(state.speed, state.yaw)
local setvel = vector.from_speed_yaw(state.speed, state.yaw)
setvel.y = -10
self.object:setvelocity(setvel)
self.object:setyaw(state.yaw)