0
\$\begingroup\$

I have been trying to implement the same aiming system as in Tank Stars, but I got a little stuck. I implemented simple stick aiming, which basically aims towards the stick movement.

enter image description here

In Tank Stars, it is much different compared to the simple aim stick. It remembers the last position and uses it as something like a pivot point.

Example

I tried to implement a virtual pivot point as in the image given. The red circle is a virtual pivot. The green circle is the stick center point, and the green arrow is the supposed stick movement. This implementation kind of works, but I don't understand how I should update that pivot point.

Is my approach correct? What is the name of this aiming system? I need a bit of help with the math behind it.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ When you say your implementation "kind of" works, can you be more precise about the specific ways in which it does not work? Walk us through a sequence of inputs that gives one result in Tank Stars, but a different result in your solution, so we can understand what specific change in behaviour you want to create. Do not count on anyone here having insider knowledge of the Tank Stars implementation, which probably does not have a published name. Instead, focus on observable behaviours and how exactly you want your outcomes to differ from what they are now. \$\endgroup\$ Commented Apr 6, 2021 at 13:28

1 Answer 1

2
\$\begingroup\$

To me it looks like the joystick is simply controlling two deltas; the Y-axis controls the pitch of the cannon and the X-axis controls the force or power of the cannon. I don't think you need to consider any pivot point for this.

Taking the pitch only as an example, you can implement it by keeping track of a baseAngle and a deltaAngle of the cannon. The current angle of the cannon is baseAngle + deltaAngle, and when the joystick is moved the deltaAngle is set to distanceMovedVertically * some_constant, where distanceMovedVertically is normalized to range [-1, 1]. some_constant is just scaling how much moving the joystick impacts the angle of the barrel.

When the joystick is released, the baseAngle is set; baseAngle = baseAngle + deltaAngle and deltaAngle is reset to zero.

Applying the same logic but using distanceMovedHorizontally allows for tuning the power or force of the cannon.

This approach yields a result that lets you control the cannon in this manner:

trajector example

\$\endgroup\$
2
  • \$\begingroup\$ It sounds like it should work. I will try it out. \$\endgroup\$ Commented Apr 7, 2021 at 5:45
  • \$\begingroup\$ I tried it out it works! But now there is a problem when facing the opposite direction. How would you handle the case when the user wants to turn in the opposite direction? My best guess is to control it through power when it reaches some threshold, rotate the tank. What do you think? Thank you. \$\endgroup\$ Commented Apr 7, 2021 at 6:59

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.