<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Maratis forum - look at / distance]]></title>
		<link>http://forum.maratis3d.com/viewtopic.php?id=717</link>
		<description><![CDATA[The most recent posts in look at / distance.]]></description>
		<lastBuildDate>Tue, 17 Sep 2013 20:55:37 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4994#p4994</link>
			<description><![CDATA[<p>It was this one:</p><p>Z-axis rotation:</p><p>Edit: Just a tweak, <a href="http://pastebin.com/p6E1Fp3q">http://pastebin.com/p6E1Fp3q</a></p>]]></description>
			<author><![CDATA[dummy@example.com (Pär)]]></author>
			<pubDate>Tue, 17 Sep 2013 20:55:37 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4994#p4994</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4988#p4988</link>
			<description><![CDATA[<p>Hi, I&#039;m trying to use that function which you have written (Anael) to make objects look only using Z-angle. but I&#039;m not sure what to put in dir, I put in a vector, when I ran it it says: attempt to index local dir (a number value)</p><p>What&#039;s up?</p>]]></description>
			<author><![CDATA[dummy@example.com (Pär)]]></author>
			<pubDate>Tue, 17 Sep 2013 11:00:57 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4988#p4988</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4648#p4648</link>
			<description><![CDATA[<p>hi,<br />would be very useful if you include an similar command as the other game engines</p><p>angle = <strong>Mathf.DeltaAngle(turretPos, targetPos)</strong><br />rotate(turret, {x, y, z}, angle, &quot;local&quot;)</p><p>Unity<br />Mathf.DeltaAngle(curPos, targetPos);<br /><span class="bbu">Calculates the shortest difference between two given angles</span><br />leadwerks<br />Math::DeltaAngle<br /><span class="bbu">This function returns the shortest distance between the two angles, relative to the first angle.</span></p>]]></description>
			<author><![CDATA[dummy@example.com (marval)]]></author>
			<pubDate>Sun, 18 Aug 2013 02:24:56 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4648#p4648</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4638#p4638</link>
			<description><![CDATA[<p>a look-at cannot operate gradually,<br />but the target yes :</p><p>- create an invisible box named &quot;TurretTarget&quot;<br />- attach a &quot;Follow&quot; behavior with a delay (for gradually moving)<br />- make your turret look-at target be &quot;TurretTarget&quot;</p><p>From script, change the target of &quot;TurretTarget&quot; depending on what the turret is supposed to look-at :<br />setBehaviorVariable(TurretTarget, 0, &quot;target&quot;, &quot;ObjectNameToLookAt&quot;)</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Fri, 16 Aug 2013 09:01:54 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4638#p4638</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4637#p4637</link>
			<description><![CDATA[<p>the Look at behaviour does not work for a turret game<br />the behaviour does not rotate the object gradually he just points instantly<br />which prevents an turret just start spinning gradually by the shortest path and only when the target comes close to a distance range</p>]]></description>
			<author><![CDATA[dummy@example.com (marval)]]></author>
			<pubDate>Fri, 16 Aug 2013 07:42:34 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4637#p4637</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4527#p4527</link>
			<description><![CDATA[<p>ok thanks <br />but I still need pass the current target (the closest enemy) to each turret in the lua script<br />the only way to do this is using the look-at behavior attached to each turret?</p>]]></description>
			<author><![CDATA[dummy@example.com (marval)]]></author>
			<pubDate>Wed, 07 Aug 2013 18:10:47 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4527#p4527</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4526#p4526</link>
			<description><![CDATA[<p>You can use a dot product between two normalized vectors :<br /><span class="postimg"><img src="http://images.tutorvista.com/cms/images/83/dot-product-image.PNG" alt="http://images.tutorvista.com/cms/images/83/dot-product-image.PNG" /></span></p><p>ex :</p><div class="codebox"><pre><code>pos1 = getPosition(object1) -- player
pos2 = getPosition(object2) -- enemy

-- get the direction of object2 if it&#039;s face is oriented toward the Y axis
dir2 = getRotatedVector(object2, vec3(0, 1, 0))

-- get the vector between object1 and object2
vec = pos1 - pos2

-- find the angle between dir2 and vec
dotValue = dot(normalize(dir2), normalize(vec)) -- dot product returns the cosinus of the angle
angle = math.acos(dotValue) -- get the angle in radian
angle = math.deg(angle) -- convert to degree</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 07 Aug 2013 16:55:11 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4526#p4526</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4525#p4525</link>
			<description><![CDATA[<p>delta yaw angle<br />how much (remaining amount/angle) an object should be rotated by in order to face completely the other object<br />and knowing this angle I can define a accuracy range so that the enemy/cpu can shoot the player</p>]]></description>
			<author><![CDATA[dummy@example.com (marval)]]></author>
			<pubDate>Wed, 07 Aug 2013 16:19:39 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4525#p4525</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4524#p4524</link>
			<description><![CDATA[<p>- the 2D rotation example only uses basic lua math (math.sqrt, math.sin etc).</p><p>- I don&#039;t understand what you mean by &quot;aiming acurracy range&quot; or delta yaw angle.</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Wed, 07 Aug 2013 15:14:28 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4524#p4524</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4523#p4523</link>
			<description><![CDATA[<p>are you using lua 3D math in the 2D rotation example?<br />for true 3D using look-at behaviour directly does not show me the delta yaw angle that I need to define &quot;aiming acurracy range&quot;</p>]]></description>
			<author><![CDATA[dummy@example.com (marval)]]></author>
			<pubDate>Wed, 07 Aug 2013 11:47:05 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4523#p4523</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4518#p4518</link>
			<description><![CDATA[<p>If you want to code a 2d rotation (around the angle Z only) you can use some arithmetic :</p><div class="codebox"><pre><code>-- get 2d vector length
function getLength2d(vec)

    return math.sqrt(vec[1]*vec[1] + vec[2]*vec[2])

end

-- normalize 2d vector
function normalize2d(vec)

    length = getLength2d(vec)
    vec[1] = vec[1] / length
    vec[2] = vec[2] / length
    return vec

end

function lookAt(object, dir, rotSpeed)

    -- compute object X dir and Y dir
    rot = getRotation(object)

    zAngle = math.rad(rot[3])
    sinZ = math.sin(zAngle)
    cosZ = math.cos(zAngle)

    YDir = normalize2d({sinZ, -cosZ})
    XDir = {-YDir[2], YDir[1]}

    -- dot products for orientation and angle
    ori = (dir[1]*XDir[1] + dir[2]*XDir[2])
    angle = math.acos(dir[1]*YDir[1] + dir[2]*YDir[2])

    if ori &lt; 0 then
        angle = - angle
    end

    rotate(object, {0, 0, 1}, math.deg(angle) * rotSpeed)

end</code></pre></div><p>For a true 3d look-at, it&#039;s more complicated, you need to use a dot product to find the angle between the objects<br />and a cross product to find the rotation axis. It&#039;s better you use the look-at behavior directly.</p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Tue, 06 Aug 2013 20:06:23 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4518#p4518</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4517#p4517</link>
			<description><![CDATA[<p>hi,anael thanks</p><p>which of those 3D math lua commands I use to calculate the delta yaw angle between two objects?</p>]]></description>
			<author><![CDATA[dummy@example.com (marval)]]></author>
			<pubDate>Tue, 06 Aug 2013 12:22:37 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4517#p4517</guid>
		</item>
		<item>
			<title><![CDATA[Re: look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4515#p4515</link>
			<description><![CDATA[<p>Hi,</p><p>for the look-at, you can use the look-at behavior (in the behavior tab), just write the name of the target.</p><p>To find the distance between objects in lua you can do :<br /></p><div class="codebox"><pre><code>pos1 = getPosition(obj1) -- use getTransformedPosition instead of getPosition if the objects are parented
pos2 = getPosition(obj2)
distance = length(pos2 - pos1)</code></pre></div><p>&quot;3d math&quot; from the wiki : <a href="http://wiki.maratis3d.org/index.php?title=Lua_functions_list">http://wiki.maratis3d.org/index.php?tit &#133; tions_list</a></p>]]></description>
			<author><![CDATA[dummy@example.com (anael)]]></author>
			<pubDate>Mon, 05 Aug 2013 22:54:56 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4515#p4515</guid>
		</item>
		<item>
			<title><![CDATA[look at / distance]]></title>
			<link>http://forum.maratis3d.com/viewtopic.php?pid=4514#p4514</link>
			<description><![CDATA[<p>hi,<br />how to rotate an object towards another?<br />how to calculate the distance between two objects?<br />I did not find lua functions for this</p>]]></description>
			<author><![CDATA[dummy@example.com (marval)]]></author>
			<pubDate>Mon, 05 Aug 2013 21:17:31 +0000</pubDate>
			<guid>http://forum.maratis3d.com/viewtopic.php?pid=4514#p4514</guid>
		</item>
	</channel>
</rss>
