<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Maratis forum - look at / distance]]></title>
	<link rel="self" href="http://forum.maratis3d.com/extern.php?action=feed&amp;tid=717&amp;type=atom"/>
	<updated>2013-09-17T20:55:37Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.maratis3d.com/viewtopic.php?id=717</id>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4994#p4994"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Pär]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1252</uri>
			</author>
			<updated>2013-09-17T20:55:37Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4994#p4994</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4988#p4988"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Pär]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=1252</uri>
			</author>
			<updated>2013-09-17T11:00:57Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4988#p4988</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4648#p4648"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[marval]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2397</uri>
			</author>
			<updated>2013-08-18T02:24:56Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4648#p4648</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4638#p4638"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2013-08-16T09:01:54Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4638#p4638</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4637#p4637"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[marval]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2397</uri>
			</author>
			<updated>2013-08-16T07:42:34Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4637#p4637</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4527#p4527"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[marval]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2397</uri>
			</author>
			<updated>2013-08-07T18:10:47Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4527#p4527</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4526#p4526"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2013-08-07T16:55:11Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4526#p4526</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4525#p4525"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[marval]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2397</uri>
			</author>
			<updated>2013-08-07T16:19:39Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4525#p4525</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4524#p4524"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2013-08-07T15:14:28Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4524#p4524</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4523#p4523"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[marval]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2397</uri>
			</author>
			<updated>2013-08-07T11:47:05Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4523#p4523</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4518#p4518"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2013-08-06T20:06:23Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4518#p4518</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4517#p4517"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[marval]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2397</uri>
			</author>
			<updated>2013-08-06T12:22:37Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4517#p4517</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4515#p4515"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[anael]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2</uri>
			</author>
			<updated>2013-08-05T22:54:56Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4515#p4515</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[look at / distance]]></title>
			<link rel="alternate" href="http://forum.maratis3d.com/viewtopic.php?pid=4514#p4514"/>
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[marval]]></name>
				<uri>http://forum.maratis3d.com/profile.php?id=2397</uri>
			</author>
			<updated>2013-08-05T21:17:31Z</updated>
			<id>http://forum.maratis3d.com/viewtopic.php?pid=4514#p4514</id>
		</entry>
</feed>
