2 objects, 2 angles and one mouse

This forum is currently in read-only mode.
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • Hello all and sorry in advance for my English.

    Let's say that these objects represent a tank;

    <img src="http://i42.tinypic.com/2ywuvsk.png" border="0" />

    • Green object is a platform on which the yellow object is mounted.
    • Green object moves in any direction in 360 degrees.
    • Yellow object can rotate at 120 degrees but only in the direction of where green object is facing.

    Yellow object should always rotate to the mouse cursor, but only when that above rule (about 120 degrees) works.

    Here is what I have and it works fine ...

    <img src="http://i41.tinypic.com/j0vdqp.png" border="0" />

    ... but when green object is facing the right direction, yellow object starts spinning like crazy around its own axis.

    I do not know how to fix it, and I know that the problem lies in the fact that the 0 degree is aimed right in Construct. Any ideas guys?

  • There's a plugin from lucid that calculates the shortest route between 2 angles even over the 0� border. This lerpangle will help, but I forgot the name of the plugin.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks for the answer tulamide!

    But today I did something like that:

    <img src="http://i42.tinypic.com/2ppkeog.png" border="0" />

    And it works very well, but now rotation isn't smooth anymore. "Rotate toward" give that nice smooth rotation and now yellow object immediately rotate to mouse.

    Any idea how to to improve this to make also smooth rotation? Because my brain is slowly becoming a overheated.

  • Without being able to test it, here's two possibilities, whose implementation would be up to you:

    1) By multiplying clamp(...) with timedelta (or a multiple of timedelta). The problem with it is, that while the angle to the mouse might change in big steps, the reaction from the turret would be slow, maybe too slow.

    2) By using lerp(). lerp basically sets some intermediate value between 2 known values, based on a t-value (the third parameter). lerp(1, 4, 0.25) would result in 1.75 (25% of the way from 1 to 4). If you use it like

    set angle to lerp(.angle, clamp(...) + Green_1.Angle, n * TimeDelta)

    it will also turn over time (with n being a number to test, the higher, the faster the turning)

    I have never worked with it, but there's a turret behavior. Is it possible that it solves some of your issues?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)