Forged Alliance Forever Forged Alliance Forever Forums 2017-01-02T18:10:34+02:00 /feed.php?f=41&t=13746 2017-01-02T12:51:04+02:00 2017-01-02T12:51:04+02:00 /viewtopic.php?t=13746&p=141534#p141534 <![CDATA[Re: Heroes mod project. How to locate a unit on 2D screen ?]]> Statistics: Posted by nine2 — 02 Jan 2017, 12:51


]]>
2017-01-02T12:13:19+02:00 2017-01-02T12:13:19+02:00 /viewtopic.php?t=13746&p=141528#p141528 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]>

It's working now :) !

For the topic purpose, this the working code that locate the unit pixel 2D position in the screen (in the example in the world main view and in the mini map).
It's for Ui side :

Code:
UnitEntity = GetUnitById(id)
local V3pos  =  UnitEntity:GetPosition()
local views = import('/lua/ui/game/worldview.lua').GetWorldViews()
for _, view in views do
   local coords = view:Project(V3pos)
   LOG("Unit 2D coordonates : " .. repr(coords))   
end


or by using GetScreenPos

Code:
UnitEntity = GetUnitById(id)
local views = import('/lua/ui/game/worldview.lua').GetWorldViews()
for _, view in views do
   local coords = view:GetScreenPos(UnitEntity)
   LOG("Unit 2D coordonates : " .. repr(coords))   
end


This offer nice possibilities. For my mod, it allows to print damages values just over the unit in realtime. But you can add value bars under the unit or some special informations.

Thanks for your valuable help Anni and Exo.

Statistics: Posted by Franck83 — 02 Jan 2017, 12:13


]]>
2017-01-01T20:04:10+02:00 2017-01-01T20:04:10+02:00 /viewtopic.php?t=13746&p=141507#p141507 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]>
I saw that the health mini bar under the unit and the unit name is are Ui feature that necessary need 2D screen position. I didn't find where getscreenpos is coded. Maybe it's hard coded.
When we rotate the camera vertically, the health mni bar and the unit name disapear. It means that the Ui appear at a fixed camera orientation.

I will try what you suggested.

Statistics: Posted by Franck83 — 01 Jan 2017, 20:04


]]>
2016-12-31T20:58:11+02:00 2016-12-31T20:58:11+02:00 /viewtopic.php?t=13746&p=141465#p141465 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]> unit[1]:GetScreenPos()
this is kinda of guesswork over here tbh.

looking at exising lua code we see that apparently getscreenpos wasnt used much, and not in faf.

local coords = self:Project(Vector(pingData.Location[1], pingData.Location[2], pingData.Location[3]))

it returns a table with x and y in it so you can use coords.y for example and it appears to be in pixels?

pingBmp.Top:Set(function() return self.Top() + coords.y - pingBmp.Height() / 2 end)

this is how you get a 2d vector from a 3d one (unit:GetPosition() returns a 3d vector for example) which should hopefully correspond to your screen space, and this line is used in worldview.lua for pings. so try that.

Statistics: Posted by Exotic_Retard — 31 Dec 2016, 20:58


]]>
2016-12-31T19:59:19+02:00 2016-12-31T19:59:19+02:00 /viewtopic.php?t=13746&p=141464#p141464 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]>
I thought same thing as you and i tried this but i still got an error on log :

WARNING:Error running lua script: ... forged alliance\mods\heroes\modules\unit_mainui.lua(431): Expected a game object. (Did you call with '.' instead of ':'?)
stack traceback:
[C]: in function `GetScreenPos'


I must have missed something

If i'm putting a repr(WorldView), i'm getting [...] GetScreenPos=moho.UIWorldView.GetScreenPos [...] in the LOG.

Statistics: Posted by Franck83 — 31 Dec 2016, 19:59


]]>
2016-12-31T13:25:05+02:00 2016-12-31T13:25:05+02:00 /viewtopic.php?t=13746&p=141443#p141443 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]>
WorldView.GetScreenPos(unit[1])
WorldView:GetScreenPos(unit[1])

Statistics: Posted by nine2 — 31 Dec 2016, 13:25


]]>
2016-12-30T22:41:03+02:00 2016-12-30T22:41:03+02:00 /viewtopic.php?t=13746&p=141429#p141429 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]>
Code:
local WorldView = import('/lua/ui/controls/worldview.lua').WorldView
--
local unit = GetSelectedUnits()
local V2pos  =  WorldView.GetScreenPos(unit[1])
LOG(repr(V2pos))   


WorldView is a right object, a repr(WorldView) is successfull but the log say that i'm missing one argument :

WARNING: Error running lua script: (vector2f|nil) = GetScreenPos(unit)
expected 2 args, but got 1


Any idea ? Thanks for your help.

Statistics: Posted by Franck83 — 30 Dec 2016, 22:41


]]>
2016-12-30T14:58:28+02:00 2016-12-30T14:58:28+02:00 /viewtopic.php?t=13746&p=141420#p141420 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]>
It's logical because we need a 2D plan to projet the unit 3D world coordonates. It depends of the camera position too and its zoom state.

But my supcom understanding is not enough good to grab a worldview object (moho.UIWorldView:__init(parent_control, cameraName, depth, isMiniMap, trackCamera)).

If somebody has some experience with this kind of usage :roll:. If not, i will try futher when i will be able to understand how it works.

Statistics: Posted by Franck83 — 30 Dec 2016, 14:58


]]>
2016-12-30T13:27:06+02:00 2016-12-30T13:27:06+02:00 /viewtopic.php?t=13746&p=141415#p141415 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]> !

Thanks a lot, i will try this.

Statistics: Posted by Franck83 — 30 Dec 2016, 13:27


]]>
2016-12-30T13:24:26+02:00 2016-12-30T13:24:26+02:00 /viewtopic.php?t=13746&p=141414#p141414 <![CDATA[Re: Heroes mod project. How to locate a unit on screen ?]]> Project()
INFO: VECTOR2 Project(self,VECTOR3) - given a point in world space, projects the point to control space
or maybe this:
GetScreenPos()

INFO: (vector2f|nil) = GetScreenPos(unit)


look at this luadoc which contains a bunch of methods in it:
http://supcom.wikia.com/wiki/LUADOC_1.5.3599

you want the ui section probably.

Statistics: Posted by Exotic_Retard — 30 Dec 2016, 13:24


]]>
2017-01-02T18:10:34+02:00 2016-12-30T13:12:52+02:00 /viewtopic.php?t=13746&p=141413#p141413 <![CDATA[How to locate a unit on 2D screen ? [Solved]]]>
How can i find the x,y position on the screen for any unit ?

I found the VECTOR3 GetPosition() that give me the x,y,z world position. But i need to find the x,y position on the screen for Ui features.

Any idea ?


My brother and me are working since one year on a RPG class system for all units in game with advanced XP, stances, Defense and Attack rating, skills, powers (buffs, debuffs, passive abilities, active ones...)
All units are able to promote as Heroes then specialize in base and prestige classes, train skills... This mod is potentially compatible with all kind of unit pack mods since it listen the unit bp to active and surcharge class features. The work is an advanced state now, functionnal as you can see in the screenshot, but it needs a lot of work (especially graphical ones, architectural improvements, a lot of balance work).

Image

The mod system in supcom give us an outstanding liberty to craft a powerfull tactical mod. The unit diversity of supcom give some impressive possibilities.

If you are excited with this possibilities as we are, stay tuned, we'll need some help in the future months.

Statistics: Posted by Franck83 — 30 Dec 2016, 13:12


]]>