@britzl dont understand that git-things
I am already on that problem. I’ve tried different sollutions. Collisions etc. but I got stuck on all them.
Now I am on the “coordinate-comparing”. Seems easy and logic. Seems…but maybe you can explain me result of the following code
go.property("maxhitpoints", 100)
go.property("hitpoints", 100)
go.property("maxenergy", 100)
go.property("energy", 100)
go.property("energyreload", 1)
go.property("energyreloadspeed", 1)
go.property("moveenergy", 10)
go.property("movespeed", 5)
go.property("ammo", 0)
local COLLISION_RESPONSE = hash("collision_response")
local RIGHTCLICKED = hash("rightclicked")
local LEFTCLICKED = hash("clicked")
local INPUT = hash("input")
local targetpos = nil
local pos = nil
local active = false
function init(self)
-- Add initialization code here
-- Remove this function if not needed
msg.post(".", "acquire_input_focus")
pos = go.get_position()
active = false
end
function update(self, dt)
-- Add update code here
-- Remove this function if not needed
--[[
if self.move and active then
local movetime = math.abs((targetpos.x - pos.x) + (targetpos.y - pos.y)) / self.movespeed
go.animate(go.get_id(),"position", go.PLAYBACK_ONCE_FORWARD, targetpos, go.EASING_LINEAR, movetime)
--go.set_position(targetpos)
self.move = false
self.active = false
end
]]
if active then
print(go.get_id())
go.set("#sprite", "tint.w", 1.0)
else
go.set("#sprite", "tint.w", 0.5)
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("activated") then
print("CROSSHAIR CLICKED ON ME " .. go.get_id())
--self.active = true
end
end
function on_input(self, action_id, action)
pos = go.get_position()
--local quat = vmath.quat_rotation_z(angle)
if action.released then
targetpos = vmath.vector3(action.x , action.y , 0)
if active then
print("POS " .. pos)
print("TARGET " .. targetpos)
self.move = true
end
print("---" .. go.get_id())
print(" math x: " .. math.abs(targetpos.x - pos.x))
print(" math y: " .. math.abs(targetpos.y - pos.y))
if math.abs(targetpos.x - pos.x) < 32 and math.abs(targetpos.y - pos.y) < 32 then
active = true
print("ACTIVATED CLICKED IN MY BOX " .. go.get_id())
else
active = false
end
end
end
I’ve attached this script it to all the units (gameobjects with sprites, collision etc named COLLECTOR, TANK, ROCKETLAUNCHER for example). 3 I’ve added to the scene for testing.
Goal should be: clicking on a unit it will activating THIS UNIT for doing something like moving or popping up a menu.
To check that, I’ve easily added the code in the UPDATE function witch tints ITSELF 100% and 50% if not active.
Now the magic!
if you click on ONE “special” unit (always the same (in my project its the COLLECTOR) 1st in the list of the OUTLINE - maybe thats the reason??) and tadaaa… ALL 3 units are 100% shown. the other 2 units are never tint 100%.
But a look in the debug.log shows the correct output which one is active.
I hope my problem is clearly enough to understand (and my germany-english good enough )
oh by the way: ignore the ON_MESSAGE thing… that message is also shown sended from the mouse/crosshair. but it has no function in that case.
And if you uncomment the move-stuff in UPDATE it will get more confuzius