Jump to content

Blow vehicle towards a point


botanist

Recommended Posts

Posted

Hmm, tried a few things, but they all don't work correctly. I wanna create a function which can blow an element (ie a vehicle) towards a point with setElementVelocity. What I've did is probably too embarrassing to post, but the solution shouldn't be too hard. Anyone?

Posted

i had somewhere a function to count angle between points, and i have a function to get an angle (comparing to Y axis) of element velocity - which you will have to "inverse" in some way. then you will be able to count it.

let me search for them

make a function from this, and return angle

viewtopic.php?f=91&t=29586&p=324244&hilit=north#p324244

and a function to get angle of velocity:

  
function getElementVelocityAngle(vehicle) 
    if (isElement(vehicle)) then 
        local vx,vy,vz = getElementVelocity(vehicle) 
        local cosX2 = (math.deg(math.atan(vx/vy))+90) 
        if (vy>0) then cosX2=cosX2+180 end 
        cosX2 = 360-cosX2 
        cosX2 = cosX2+270 
        if (cosX2 > 360) then cosX2 = cosX2-360 end 
        return cosX2 
    end 
end 
  

idk how to reverse it :P

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted
function blowElement(element,x,y,z,speed) 
    local ex,ey,ez = getElementPosition(element) 
    x,y,z = x-ex,y-ey,z-ez 
    local dist = math.sqrt(x*x+y*y+z*z) 
    x = x*speed/dist 
    y = y*speed/dist 
    z = z*speed/dist 
    setElementVelocity(element,x,y,z) 
end 

Didn't test, but it should work.

-

Posted

remi-x - this was for getting this, not setting..

Doomed - lol, this makes sense.. probably all that math makes my brain crazy and now i want to solve every problem with this o_O

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...