2 objects, 2 angles and one mouse

For questions about using Classic.

Post » Sat Sep 14, 2013 6:33 pm

Hello all and sorry in advance for my English.

Let's say that these objects represent a tank;

- 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 ...



... 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?
B
12
S
4
G
2
Posts: 13
Reputation: 1,235

Post » Tue Sep 17, 2013 8:07 am

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.
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Tue Sep 17, 2013 2:06 pm

Thanks for the answer tulamide!

But today I did something like that:

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.
B
12
S
4
G
2
Posts: 13
Reputation: 1,235

Post » Wed Sep 18, 2013 10:59 am

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?
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests