Skip to content

Commit

Permalink
add task turntopoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Umbrella167 committed Apr 26, 2024
1 parent f34bf68 commit 0167637
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
5 changes: 1 addition & 4 deletions Core/tactics/play/BOSS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ local interPos = function(enemyNum)
end
gPlayTable.CreatePlay{
firstState = "Init",

["Init"] = {
switch = function()
return "Run"
Expand All @@ -54,12 +53,10 @@ firstState = "Init",
Assister = task.stop(),
match = "[A]"
},

["Run"] = {
switch = function()
debugEngine:gui_debug_msg(CGeoPoint(0,0),player.infraredCount("Assister"))
end,
Assister = task.stop,--task.goCmuRush(function()return interPos(function() return getTheirDribblingPlayer() end)end, toBallDir("Assister"),_,_,Utils.Polar2Vector(700,(interPos(function() return getTheirDribblingPlayer() end) - player.pos("Assister")):dir())),
Assister = task.goCmuRush(function()return interPos(function() return getTheirDribblingPlayer() end)end, toBallDir("Assister"),_,_,Utils.Polar2Vector(700,(interPos(function() return getTheirDribblingPlayer() end) - player.pos("Assister")):dir())),
match = "[A]"
},

Expand Down
2 changes: 0 additions & 2 deletions Core/tactics/play/chanllenge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ firstState = "Init",
debugEngine:gui_debug_arc(firstPos[1],600,0,360,4)
debugEngine:gui_debug_arc(firstPos[2],600,0,360,1)
debugEngine:gui_debug_arc(firstPos[3],600,0,360,1)


-- 如果机器人拿到球并且 与目标角度相差小于3度那么传球
if task.playerDirToPointDirSub("Assister",player.pos("Kicker")) < 3 and player.infraredCount("Assister") > 5 then
return "shoot"
Expand Down
11 changes: 7 additions & 4 deletions Core/tactics/skill/CircleRun.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
function CircleRun(task)

local pos = task.pos or CGeoPoint(30,80)
local vel = task.vel or -5

matchPos = function()
return ball.pos()
end

execute = function(runner)
task_param = TaskT:new_local()
task_param.executor = runner
task_param.player.pos = task.pos
task_param.player.rotvel = task.rotVel
task_param.player.pos = pos
task_param.player.rotvel = vel
task_param.player.flag = flag.dribbling
return skillapi:run("CircleRun", task_param)
end

return execute, matchPos
end

Expand Down
2 changes: 2 additions & 0 deletions ZBin/lua_scripts/worldmodel/param.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module(..., package.seeall)
-- lengthRatio = 1.5
-- widthRatio = 1.5
-- stopRatio = 1.1
rotPos = CGeoPoint(80,80)
rotVel = 3.8
-----------------------
infraredMinDist = 115
-----------------------
Expand Down
50 changes: 50 additions & 0 deletions ZBin/lua_scripts/worldmodel/task.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,56 @@ module(..., package.seeall)

--- /// /// --- /// /// --- /// /// --- /// /// --- /// /// ---


function TurnToPoint(role, p, speed)
-- 函数说明:
--使用前提:拿到球之后
--功能:以球为中心旋转到目标点,需要在State层跳出
--参数说明
-- role 使用这个函数的角色
-- p 指向坐标
-- speed 旋转速度 [1,10]
local p1 = p
if type(p) == 'function' then
p1 = p()
else
p1 = p
end
if speed == nil then
speed = param.rotVel
end
debugEngine:gui_debug_x(p1,6)
local toballDir = (p1 - player.rawPos(role)):dir() * 57.3
local playerDir = player.dir(role) * 57.3
local subPlayerBallToTargetDir = toballDir - playerDir
-- local Subdir = math.abs(toballDir-playerDir)
debugEngine:gui_debug_msg(CGeoPoint:new_local(1000,380),toballDir .. " " .. playerDir,4)
debugEngine:gui_debug_msg(CGeoPoint:new_local(1000,220),math.abs(toballDir-playerDir) .. " " .. subPlayerBallToTargetDir,3)
if math.abs(toballDir-playerDir) > 4 then
if subPlayerBallToTargetDir < 0 then
-- 顺时针旋转
-- debugEngine:gui_debug_msg(CGeoPoint(1000, 1000), "顺时针")
local ipos = CGeoPoint(param.rotPos:x(), param.rotPos:y() * -1) --自身相对坐标 旋转
local ivel = speed * -1
local mexe, mpos = CircleRun {pos = ipos , vel = ivel}
return { mexe, mpos }
else
-- 逆时针旋转
-- debugEngine:gui_debug_msg(CGeoPoint(1000, 1000), "逆时针")
local ipos = param.rotPos --自身相对坐标 旋转
local ivel = speed

local mexe, mpos = CircleRun {pos = ipos , vel = ivel}
return { mexe, mpos }
end
else
local idir = (ball.pos() - player.pos(role)):dir()
local pp = ball.pos() + Utils.Polar2Vector(50, idir)
local mexe, mpos = GoCmuRush { pos = pp, dir = idir, acc = 50, flag = 0x00000100 + 0x04000000, rec = 1, vel = v }
return { mexe, mpos }
end
end

function playerDirToPointDirSub(role, p) -- 返回 某座标点 球 playe 的角度偏差
if type(p) == 'function' then
p1 = p()
Expand Down

0 comments on commit 0167637

Please sign in to comment.