• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] Missiles and math

Status
Not open for further replies.
Level 9
Joined
Sep 5, 2007
Messages
358
Hello!

I'm currently working on a spell that requires missiles to behave a bit differently than usual.

Normally, when a missile is launched at a target position, the angle is calculated and set towards the target position and then we only need to apply the velocity to the missile's position.

In this case I want something a little bit different.

See when you have a missile that is targeting a unit, and that unit is moving? The missile moves and follows the target unit until colliding with it.

I'm looking for a similar behavior but for target points.
Basically the effect I'm looking to achieve is when a missile is launched towards a direction but slowly rotates to the target point, making a sort of parabola trajectory.

I sketched an image example of the effect I'm trying to do:
attachment.php

(Yap, awesome drawing :gg:)

Math is my weakest point, as you might have guessed already.

Now, how can I achieve this? The solution is probably simpler than I'm 'picturing' it.
I've already tried a few ugly methods and I only got totally weird trajectories.

Any sample Jass code or simply pseudo-code accompained with explanation would help greatly!

Thanks.
 

Attachments

  • Missile arc example.jpg
    Missile arc example.jpg
    24.1 KB · Views: 256
Level 5
Joined
Jun 16, 2004
Messages
108
Well math is not my strong point, but here are two things I thought up.

I am assuming you want an object to travel in a sideways arc to the target point rather than through the air. If you are already familiar with using a parabolic trajectory through the air, you can transform that to work for this situation. You can simply take the flying height value you would normally get and use it differently. Say you have a missile moving in a straight line towards the target point. To use it with the parabola's distance value you could simply take the x/y of the position of where the missile would be (if it was traveling straight), then polar offset it by the parabola distance value, angled PI / 2 radians ccw or cw.

Simple pseudo code to demonstrate what I mean above:
JASS:
real x
real y // assume x/y are the current position were the missile traveling in a straight line
. . .
local real x2
local real y2

set x = x + Cos(angle) * offset // typical straight line movement
set y = y + Sin(angle) * offset // you would want to store these x/y values somewhere as the x2/y2 is offset from them
set x2 = x + Cos(angle + PI / 2) * parabola_offset
set y2 = y + Sin(angle + PI / 2) * parabola_offset // parabola offset ccw

call SetUnitX(missile, x2)
call SetUnitY(missile, y2)

Or if you are fine with a simple half circle arc you can just take the mid point of the target point and source point, store it, store an angle from the mid point to the source point, and finally store an angle increment value. From that you simply need to make a polar offset from the mid point traveling along a static offset (distance from mid point to source point) and changing angle.

The second method is simpler but does not offer control over the arc height since it would simply be the radius of a circle whose opposing sides are the target point and the cast point.
 
Level 9
Joined
Sep 5, 2007
Messages
358
Hey Halo, thanks for helping me out.

However, I'm afraid I'm not being able to implement this successfully.
I'm not so familiar with the parabolic function either, that's probably why.

I'm not sure how I would go about calculating the parabola_offset.

Would you mind explaining this a little bit further?
 
Level 5
Joined
Jun 16, 2004
Messages
108
Well I did not put any effort into readability but hopefully you get the idea with each since there is not much to the code. If you will notice, the one that uses the parabola uses the same distance for its curve every time, whereas the second spell's arc height depends on the distance of your cast.

The parabola function is something I made a long time ago, there are probably better ways of doing it.

You can fiddle around with the curve distance in the first one by changing the 200. in the line:
> call tt.parabola(duration, 200., interval)

And whether it curves cw or ccw depends on whether subtracting or adding to tt.sangle in this line:
> set x2 = tt.sx + Cos(tt.sangle + 3.1415 / 2.) * offset

The two examples calculate the number of iterations ahead of time, which might not be something you would want. In any case, these two examples are meant to demonstrate what I said above, rather than be code you can copy and paste, though feel free to do that if you feel like it.
 

Attachments

  • tets2.w3x
    49 KB · Views: 60
Status
Not open for further replies.
Top