• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Math Height Problem

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
Hi, i need some help with some math. im creating a meteor spell, but i have some problem calculating how much i should decrease the meteor's height every 0.03 sec. its height must be 0 when it reach the target location

what i want is so the meteor will look realistic even if u target on the caster or far away from it

'MoveDist' how much the meteor move every interval.
'Interval' How often i run it
'Distance' How far between the caster and target location
'MaxHeight' The height it have when i create it
'Height' Its Current Height

You dont have to use all of these ofc

attachment.php
 

Attachments

  • Pic.JPG
    Pic.JPG
    45 KB · Views: 317
Last edited:
If you're using constant vertical acceleration, the formula will be based on the acceleration and the time.

V' = V + at

Where V' is the new vertical speed after t seconds (and hence the height you will decrease)
And V is the current vertical speed.
a is the acceleration.

a = /\V/t
a = (/\S/t)/t
a = /\S/t²

/\S is the distance the meteor will "walk" (just don't know the word to use >.>), so it's MaxHeight
and t is the time taken for it, so, fulltime.

Applying to the first formula, we have:

V' = V + MaxHeight/Fulltime² * 0.03

Guess it works...

BTW, nice paint picture :D
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
You're wrong.
Δv = a*t -> This is for linear acceleration.

Δs = v*t -> This is for linear velocity.

For linear acceleration, this is the right formula:
Δs = a*t2/2 + vi*t
Where vi is the initial velocity.

In any case, this is not what he wants. I don't know where you pulled out acceleration but to me, his trajectory looks like a straight line, not a parabola. Therefore his acceleration should be 0, and you will have linear velocity so:
Δs = v*t
That should solve pretty much everything you need.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Δv = a*t -> This is for linear acceleration.

V = V0 + a*t ? o.0

By the way, these sub/sup tags are cool.

Δs = v*t

so v * t in my case is? im not so good at math :p

Yes, since your movement is linear, you don't need to take into account acceleration (gravity in most cases), which means that your movement is only based on your object's velocity.

To check what the velocity should be, you should do something like this

V = (Dist/Time)*(interval)

Which I figure will only work for intervals below 1 second, else you'd need to do

V = (Dist/Time)/(1/interval)

But since there is no chance your intervals will be above 1...
 
Level 11
Joined
Apr 6, 2008
Messages
760
i changed my mind abit i dont need fulltime (if u target close to the caster it will look wierd) so need something based on

'MoveDist' how much the meteor move every interval. lets say this is 30 or something
'Interval' How often i run it
'Distance' How far between the caster and target location
'MaxHeight' The height it have when i create it
'Height' Its Current Height

Edit:

Can u base a "Time" on height and distance so it will look realistic?
 
Last edited:
Level 20
Joined
Apr 22, 2007
Messages
1,960
GhostWolf said:
V = V0 + a*t ? o.0
Δv = v - vi, so yes.

GhostWolf said:
V = (Dist/Time)*(interval)

Which I figure will only work for intervals below 1 second, else you'd need to do

V = (Dist/Time)/(1/interval)
lolwut? Both of those are algebraicly the same.

So I guess I can try this out.
MoveDist is length of the velocity vector, which will be split in 3 parts, XY axis, and Z axis (height).
JASS:
local real dx = TargetX - CasterX
local real dy = TargetY - CasterY
local real dz = (MaxHeight + GetLocationZ(CasterLoc)) - GetLocationZ(Target)
// Each of these constants represent the delta s vector.

local real k = MoveDist*Interval/(SquareRoot(dx*dx + dy*dy + dz*dz) + 0.01)
// Here I am setting delta s's length to that of MoveDist per Interval
// I added 0.01 to avoid division by 0.

set xVelocity = dx*k
set yVelocity = dy*k
set zVelocity = dz*k
// These lines will set the x, y and z velocity for the meteor, to that which needs to be updated per Interval seconds. I'm assuming by Interval you mean frequency, and therefore something like 0.03 seconds, not 60 frames per second.

So you'd just add x, y and z Velocity to the position of the meteor every Interval seconds.
 
Level 11
Joined
Apr 6, 2008
Messages
760
well thank you all alot but i have a bit of a problem with it :/ the dummy just moves to the middle or the map.

JASS:
scope meteor initializer init

private struct Data
unit caster
unit dummy

real Cx
real Cy
real Tx
real Ty
real dx
real dy
real dz

real xVelocity
real yVelocity
real zVelocity
real Delta

location Cloc //dont need to save some of this shit but nvm it
location Tloc

static integer array Ar
static integer Total = 0
static timer Time = CreateTimer()
    
    static method create takes unit u,location Tloc returns Data
        local Data Dat = Data.allocate()
        local real angle 
        
        set Dat.caster = u
        set Dat.Cx = GetUnitX(Dat.caster)
        set Dat.Cy = GetUnitY(Dat.caster)
        set Dat.Cloc = Location(Dat.Cx,Dat.Cy)
        set Dat.Tloc = Tloc
        set Dat.Tx = GetLocationX(Dat.Tloc)
        set Dat.Ty = GetLocationY(Dat.Tloc)
        set Dat.dx = Dat.Tx - Dat.Cx
        set Dat.dy = Dat.Ty - Dat.Cy
        set angle = Atan2(Dat.Ty-Dat.Cy,Dat.Tx-Dat.Cx)
        set Dat.dz = (500 + GetLocationZ(Dat.Cloc)) - GetLocationZ(Dat.Tloc)
        set Dat.dummy = CreateUnit(GetOwningPlayer(Dat.caster),'hfoo',Dat.Cx,Dat.Cy,angle*bj_RADTODEG)
        set Dat.Delta = 30*0.03/(SquareRoot(Dat.dx*Dat.dx + Dat.dy*Dat.dy + Dat.dz*Dat.dz) + 0.01)
        
            
        call UnitAddAbility(Dat.dummy,'Amrf')
        call SetUnitFlyHeight(Dat.dummy,500,0.)
        call UnitRemoveAbility(Dat.dummy,'Amrf')
        
        if Dat.Total == 0 then
            call TimerStart(Dat.Time,.03,true,function Data.Loop)
        endif
        
        set Dat.Ar[Dat.Total] = Dat
        set Dat.Total = Dat.Total + 1
        
        call RemoveLocation(Tloc)
        
        set Tloc = null
        set u = null
        
        return Dat
    endmethod
    
    static method Loop takes nothing returns nothing
        local Data Dat
        local integer i = 0
        
        loop
            exitwhen i >= Dat.Total
            set Dat = Dat.Ar[i]
            
            set Dat.xVelocity = Dat.dx*Dat.Delta
            set Dat.yVelocity = Dat.dy*Dat.Delta
            set Dat.zVelocity = Dat.dz*Dat.Delta
            
            if Dat.zVelocity > 0 then
                call SetUnitX(Dat.dummy,Dat.xVelocity)
                call SetUnitY(Dat.dummy,Dat.yVelocity)
                call SetUnitFlyHeight(Dat.dummy,Dat.zVelocity,0.)
            else
                set Dat.Total = Dat.Total - 1
                set Dat.Ar[i] = Dat.Ar[Dat.Total]
                set i = i - 1
                call Dat.destroy()
            endif
            
            set i = i + 1
        endloop
        
        if Dat.Total == 0 then
            call PauseTimer(Dat.Time)
        endif
    endmethod
endstruct
 
Last edited:
Level 7
Joined
Jul 20, 2008
Messages
377
A simple lesson in Newtonian physics:

The delta notation means "change in."

Velocity is the change in position (v = Δx)
Acceleration is the change in velocity (a = Δv)

If you've worked with vectors in math, velocity is basically a vector. The cool thing about vectors is that the components are independent of each other. In short, you could have independent X and Y velocities and just move the object first in the X direction THEN the Y direction or in the reverse order (whatever you prefer). To receive the angle from the velocity components, you calculate tan-1 (vy/vx). Magnitude is SQRT(vx2 + vy2).

A vector has a magnitude and direction. However, you can break up its magnitude & direction into components:

vx = Magnitude*cos (angle)
vy = Magnitude*sin (angle)


Sorry if you already know this, I'm just trying to help you understand Hindy's post.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
It's important to note that all of the formulas are different when working in a 3D system. In fact, magnitude becomes SquareRoot(vx2 + vy2 + vz2). As for the polar coordinates, I always forget spherical polar coordinates but yeah it's not as simple as length*cos or sin.
 

peq

peq

Level 6
Joined
May 13, 2007
Messages
171
I often use something like this for linear movement:

JASS:
static method create .....
	....
	
	//the start point:
	set .startX = ...
	set .startY = ...
	set .startZ = ...
	
	//the end Point
	set endX = ...
	set endY = ...
	set endZ = 0.
	
	//time to travel
	set .endTime = ... // any value > 0
	
	//calculate distance to travel
	set distX = endX - StartX
	set distY = endY - StartY
	set distZ = endZ - StartZ
	
	//calculate speed
	// v = s / t
	set .speedX = distX / .endTime
	set .speedY = distY / .endTime
	set .speedZ = distZ / .endTime
	
	//start at time == 0
	set .time = 0.
	

	
	....
endmethod

//called every INTERVAL second
method dostep ...
	...
	
	//update time
	set .time = .time + INTERVAL
	
	
	....
	
	//update position
	// s = v * t
	set .posX = .startX + .speedX * .time
	set .posY = .startY + .speedY * .time
	set .posZ = .startZ + .speedZ * .time
	
	
	
	
	....
	
	if .time >= .endtime then
		//booom
		...
		call .destroy()
	endif	
	
	...
endmethod
 
Status
Not open for further replies.
Top