Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are 2 things you should fix:</p> <ul> <li><p>Actually the <code>directionY</code> is (lets review your formula):</p> <pre><code>float directionY = pSceneTouchEvent.getY() - gun.getY(); </code></pre></li> <li><p>Your <code>directionX</code> and <code>directionY</code> are the shift elements of the touch position compare to your gun's <code>[top,left]</code> world position => so your <strong>calculated angle</strong> is actually the rotation around this gun's <code>[top,left]</code> position. Hence, thing should be:</p> <pre><code>gun.setRotationCenter(0, 0); </code></pre></li> </ul> <p>where (0,0) is the local [top, left] relative position to set the anchor for the rotation in the gun.</p> <p><strong>NOTE:</strong></p> <p>You should learn more about the Physics in AndEngine (Box2D). To do things as you want, normally, you should do as follows:</p> <ul> <li>Create a <strong><code>fix anchor body</code></strong> (may be a circle body) at where you want your <code>gun</code> to rotate around.</li> <li>Create a <strong><code>RevoluteJoint</code></strong> to pin your Gun with this anchor.</li> <li>Create and Dispose a <strong><code>Mouse Joint</code></strong> between your gun and a mouse point every time you <strong>Touch</strong> your gun and <strong>Release</strong> your touch.</li> </ul> <p>You can see the examples of AndEngine Examples in <code>Physics\Using a RevoluteJoint + MouseJoint</code>.</p> <p>This will help you create normal interactions as happened in the real world, regardless of calculating positions, rotations, or velocity of your body objects (cause physics engine will do them for you).</p> <p>And more, you can apply the same mechanism (by encapsulating the above procedure in functions or class) on any object within your game.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload