+ Reply to Thread
Results 1 to 8 of 8

Thread: Drone Base Model (DBM)

  1. #1
    billywitchdoctor.com Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    2,300

    Default Drone Base Model (DBM)

    This is just a base for flying drones. Credits to Divran for the applyTorque.

    Description:
    An aim based E2 drone with acceleration.

    To use:
    Place the drone on its own or on another prop. Change weight if needed.
    Wire W A S D and Ent to an Adv Pod W A S D Entity outputs.
    Wire Active of a cam controller to the adv pod active.
    Wire Position and Direction from cam controller to E2 Pos and Eye respectively.

    Code:
    @name Drone Base Model (DBM)
    @inputs W A S D Ent:entity
    @outputs Cam:vector Eye:vector E:entity
    @persist Pos:vector Speed1 Speed2 E:entity Driver:entity
    
    if(first() | duped()){
    
        if (entity():isWeldedTo()) {
            E = entity():isWeldedTo()
        } else {
            E = entity()
        }
    
        Speed1 = 5
        Speed2 = 5
        Pos = E:pos()
        runOnTick(1)
    }    
    Driver = Ent:driver()
    
    E:applyForce(( (-E:pos() + Pos)*(Speed1+Speed2)/2 - E:vel())*E:mass())
    
    Torque = E:toLocal(rotationVector(quat(Driver:eyeAngles())/quat(E))+E:pos())
    E:applyTorque((Torque*20-E:angVelVector()*10)*E:inertia())
    
    if (E:isPlayerHolding()) {Pos = E:pos()}
    
        if (Driver) {
            Eye = Driver:eye()
            if (W) {Pos += Eye*Speed1}
            if (S) {Pos -= Eye*Speed2}
            if (A) {Pos += -E:right()*10}
            if (D) {Pos += E:right()*10}
    
    if (W) {Speed1 += (Speed1 < 50)/5} else {Speed1 -= (Speed1>5)/2}
    if (S) {Speed2 += (Speed2 < 40)/5} else {Speed2 -= (Speed2>5)/2}
    Cam = E:pos() + vec(0,0,0) + E:vel()/66.7 #change vec(0,0,0) for cam offset.
    
    }
    Last edited by Whosdr; 09-06-2010 at 08:56 AM.
    .siht daer ot gniyrt emit detsaw ev'uoY

  2. #2
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: Drone Base Model (DBM)

    TADAA:
    Code:
    @name Drone Base
    @inputs [Pod Cam]:wirelink Active E:entity
    @persist ForwardSpeed SideSpeed UpSpeed Pos:vector TargetQuat:quaternion
    @persist ForwardAcc ForwardTopSpd SideAcc SideTopSpd UpAcc UpTopSpd TurnSpeed ForceMul QuatMul1 QuatMul2 CameraDistance CameraHeight ShiftBoost
    @trigger 
    
    if (first()|duped()) {
        #CHANGE THESE TO WHAT YOU WANT
        ForwardAcc = 0.8        #How fast it accelerates forward (W & S)
        ForwardTopSpd = 20      #Forward Top Speed
        SideAcc = 0.8           #How fast it accelerates to the side (A & D)
        SideTopSpd = 20         #Side Top Speed
        UpAcc = 0.8             #How fast it accelerates up and down (Space & Alt)
        UpTopSpd = 2            #Up/Down Top Speed
        TurnSpeed = 0.08        #How fast it turns
        ForceMul = 40           #ApplyForce Multiplier
        QuatMul1 = 1000         #Quaternion Multiplier nr 1
        QuatMul2 = 20           #Quaternion Multiplier nr 2
        CameraDistance = 200    #How far behind the prop the camera is
        CameraHeight = 50       #How far above the prop the camera is
        ShiftBoost = 50         #How much extra boost shift gives to speed (is in percent!!!)
        
        #Do not change anything below here unless you know what you are doing
    }
    
    runOnTick(Active&E)
    
    if (~Active) {
        if (Active) {
            TargetQuat = quat(Pod["Entity",entity]:driver():eyeAngles())
            Cam["Parent",entity] = E
            Pos = E:pos()
        }
    }
    
    if (Active ) {
        #Controls
        W = Pod["W",number]
        A = Pod["A",number]
        S = Pod["S",number]
        D = Pod["D",number]
        Space = Pod["Space",number]
        Alt = Pod["Alt",number]
        Shift = Pod["Shift",number]
        Driver = Pod["Entity",entity]:driver()
        
        #Fly
        if (W|S) {
            ForwardSpeed = clamp(ForwardSpeed+(W-S)*ForwardAcc,-ForwardTopSpd,ForwardTopSpd)
        } else {
            ForwardSpeed -= clamp(ForwardSpeed,-ForwardAcc,ForwardAcc)
        }
        if (A|D) {
            SideSpeed = clamp(SideSpeed+(D-A)*SideAcc,-SideTopSpd,SideTopSpd)
        } else {
            SideSpeed -= clamp(SideSpeed,-SideAcc,SideAcc)
        }
        if (Space|Alt) {
            UpSpeed = clamp(UpSpeed+(Space-Alt),-UpTopSpd,UpTopSpd)
        } else {
            UpSpeed -= clamp(UpSpeed,-ForwardAcc,ForwardAcc)
        }
        Pos += (TargetQuat:forward() * ForwardSpeed + TargetQuat:right() * SideSpeed + TargetQuat:up() * UpSpeed) * (1+ShiftBoost/100*Shift)
        E:applyForce(((Pos-E:pos())*ForceMul-E:vel())*E:mass())
        
        #Aim
        TargetQuat = slerp(TargetQuat,quat(Driver:eyeAngles()),TurnSpeed)
        Torque = E:toLocal(rotationVector(TargetQuat/quat(E))+E:pos())
        E:applyTorque((Torque*QuatMul1-E:angVelVector()*QuatMul2)*E:inertia())
        
        #Camera
        Cam["Position",vector] = Pos - Driver:eye() * CameraDistance + vec(0,0,CameraHeight)
        Cam["Direction",vector] = Driver:eye()
    }
    The only drawback is it uses SLIGHTLY MORE ops than Whosdr's (like 200 more)
    Last edited by Divran; 02-03-2010 at 02:26 PM.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  3. #3
    aka Colonel Never Online Colonel Thirty Two's Avatar
    Join Date
    Oct 2009
    Posts
    2,683
    Blog Entries
    5

    Default Re: Drone Base Model (DBM)

    Why is there 2 different code outlines? O_o

  4. #4
    billywitchdoctor.com Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    2,300

    Default Re: Drone Base Model (DBM)


    One is [code][/code] which you can copy, but isn't as good to read.
    The one one is [highlight="e2"][/highlight] which can't be directly copied, but is easy to read.
    .siht daer ot gniyrt emit detsaw ev'uoY

  5. #5
    Wire Noob Xgraver's Avatar
    Join Date
    Apr 2009
    Posts
    11

    Default Re: Drone Base Model (DBM)

    Sorry for bump, but how to change prop direction in second code? So the side would be forward for example.

  6. #6
    Banned GalvazimGX's Avatar
    Join Date
    Sep 2008
    Posts
    159

    Default Re: Drone Base Model (DBM)

    WHOA! Did you even check the dates, pal?

  7. #7
    billywitchdoctor.com Whosdr's Avatar
    Join Date
    Dec 2008
    Posts
    2,300

    Default Re: Drone Base Model (DBM)

    No, it's no problem. I'm quite active in the forums.
    Code:
    Torque = E:toLocal(rotationVector(quat(Driver:eyeAngles()+ang(0,90,0))/quat(E))+E:pos())
    .siht daer ot gniyrt emit detsaw ev'uoY

  8. #8
    Wire Noob Xgraver's Avatar
    Join Date
    Apr 2009
    Posts
    11

    Default Re: Drone Base Model (DBM)

    Thanks for helping.

+ Reply to Thread

LinkBacks (?)

  1. 02-03-2010, 11:51 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots