Transformer

View previous topic View next topic Go down

Transformer

Post by DanielLC on Sat Oct 30, 2010 3:59 pm

This is an old model of mine, though I have never posted it since I added the walker mode.

I've been having trouble with the hovercraft mode. I can't get it to both fix its rotation at the speeds I want, and not have crazy gyrations. Part of the problem is the extra chips necessary for the walker mode.

I'm working on something that would fix this, though I'm doing it on another model.

Press Q for car, W for hovercraft, and E for walker.

Code:
Val
{
  ANGLE00(default=180,min=-360,max=360)
  ANGLE10(default=180,min=-360,max=360)
  ANGLE01(default=0,min=-360,max=360)
  ANGLE11(default=0,min=-360,max=360)
  ANGLE21(default=0,min=-360,max=360)
  ANGLE31(default=0,min=-360,max=360)
  ANGLE02(default=0,min=-360,max=360)
  ANGLE12(default=0,min=-360,max=360)
  ANGLE22(default=180,min=-360,max=360)
  ANGLE32(default=180,min=-360,max=360)
  ANGLE03(default=0,min=-360,max=360)
  ANGLE13(default=0,min=-360,max=360)
  ANGLE23(default=-90,min=-360,max=360)
  ANGLE33(default=-90,min=-360,max=360)
  ANGLE(default=0, min=-1000000, max=1000000)
  AX(default=0, min=-3.15, max=3.15)
  AY(default=0, min=-3.15, max=3.15)
  AZ(default=0, min=-3.15, max=3.15)
  BRAKE0(default=0, max=100000, step=80)
  BRAKE(default=0, max=100000, step=80)
  DAMP(default=0.2, min=0.2, max=1)
  DAX(default=0, min=-6.3, max=6.3)
  DAY(default=0, min=-6.3, max=6.3)
  DAZ(default=0, min=-6.3, max=6.3)
  ADAX(default=0, min=-6.3, max=6.3)
  ADAY(default=0, min=-6.3, max=6.3)
  ADAZ(default=0, min=-6.3, max=6.3)
  ENGINE0(default=0, min=-20000, max=20000, step=20000)
  ENGINE(default=0, min=-20000, max=20000, step=20000)
  HANDLE0(default=0, min=-45, max=45, step=2)
  HANDLE(default=0, min=-45, max=45, step=2)
  LEFT(default=0, min=-1000000, max=1000000)
  NE(default=0, min=-1000000, max=1000000)
  NW(default=0, min=-1000000, max=1000000)
  RIGHT(default=0, min=-1000000, max=1000000)
  SE(default=0, min=-1000000, max=1000000)
  SPEED(default=0, min=-1000000, max=1000000, step=50000)
  THRUST(default=0, min=-10000000, max=10000000)
  SW(default=0, min=-1000000, max=1000000)
  TRANSFLG(default=0, max=1)
  TRANSA(default=90, max=90)
  TRANSB(default=0, max=90)
  TRANSC(default=0, max=90)
  TRANS0(default=0, max=2)
  TRANS1(default=0, max=2)
  Y(default=50, max=10000)
  TIME(default=0,min=-3.15,max=5)
  CRAWL(default=0,min=-0.4,max=0.4)
  STRIDE(default=2,min=0,max=5)
}
Key
{
   0:Engine0(step=500),SPEED(step=30000),CRAWL(step=0.02)
   1:Engine0(step=-500),SPEED(step=-30000),CRAWL(step=-0.02)
   2:Handle0(step=-0.5),ANGLE(step=-10000)
   3:Handle0(step=0.5),ANGLE(step=10000)
   4:Y(step=-1)
   5:Y(step=1)
}
Body
{
  Core(){
    N:Trim(spring=0.2, damper=Damp){
      N:Rudder(angle=Handle){
W:Rudderf(option=1,angle=ANGLE00){
E:Chip(angle=ANGLE01){
E:Chip(angle=ANGLE02){
E:Wheel(option=1, angle=TRANSA, power=-ENGINE, brake=Brake, color=#000000){}
E:Jet(angle=TRANSA, power=-NW, color=#000000){}
}}}
E:Rudderf(option=1,angle=ANGLE00){
W:Chip(angle=ANGLE11){
W:Chip(angle=ANGLE12){
W:Wheel(option=1, angle=TRANSA, power=ENGINE, brake=Brake, color=#000000){}
W:Jet(angle=TRANSA, power=-NE, color=#000000){}
}}}
      }
    }
    S:Trim(spring=0.2, damper=Damp){
      S:Rudder(angle=-Handle){
W:Rudderf(option=1,angle=ANGLE00){
E:Chip(angle=ANGLE01){
E:Chip(angle=ANGLE02){
E:Wheel(option=1, angle=TRANSA, power=-ENGINE, brake=Brake, color=#000000){}
E:Jet(angle=TRANSA, power=-SW, color=#000000){}
}}}
E:Rudderf(option=1,angle=ANGLE00){
W:Chip(angle=ANGLE11){
W:Chip(angle=ANGLE12){
W:Wheel(option=1, angle=TRANSA, power=ENGINE, brake=Brake, color=#000000){}
W:Jet(angle=TRANSA, power=-SE, color=#000000){}
}}}
      }
    }
    W:Rudderf(option=1,angle=ANGLE10){
      E:Chip(angle=ANGLE21){
        E:Rudderf(option=1,angle=-TRANSB){
          W:Chip(angle=ANGLE22){
            W:Wheel(name=M1, option=1, angle=ANGLE23, power=Engine, brake=Brake, color=#000000){}
            W:Jet(angle=ANGLE23, power=LEFT, color=#000000){}
          }
        }
      }
    }
    E:Rudderf(option=1,angle=ANGLE10){
      W:Chip(angle=ANGLE31){
        W:Rudderf(option=1,angle=TRANSB){
          E:Chip(angle=ANGLE32){
            E:Wheel(name=M2, option=1, angle=ANGLE33, power=-Engine, brake=Brake, color=#000000){}
            E:Jet(angle=ANGLE33, power=RIGHT, color=#000000){}
          }
        }
      }
    }
  }
}
Lua
{
function mod(A)
  if A > math.pi
  then
    A=A-2*math.pi
  else
  if A < -math.pi
  then
    A=A+2*math.pi
  end
  end
  return A
end

function absmax(a,b)
  if(math.abs(a)>b)
  then
    return b*a/math.abs(a)
  else
    return a
  end
end

function sqr(a)
  return a*a
end

function len2(x,y)
  return math.sqrt(x*x+y*y)
end

function len3(x,y,z)
  return math.sqrt(x*x+y*y+z*z)
end

function findy(foot)
  time=mod(TIME+foot*math.pi)

  if time<0
  then
    return sqr(math.sin(time))*0.7-1.2
  else
    return -1.2
  end
end

function findz(foot)
  time=mod(TIME+foot*math.pi)

  if time<0
  then
    cos=math.cos(time)-0.5-time/math.pi
  else
    cos=0.5-time/math.pi
  end
  return STRIDE*cos
end

function findangle2(y,z)
  r=len3(2,y,z)
  return math.pi-math.acos((5.84-sqr(r))/4.4)
end

function findangle1(angle2,y,z)
  r=len3(2,y,z)
  del=math.acos((sqr(r)-3.84)/(2*r))
  r2=len2(2,z)
  return -math.atan(y/r2)-del
end

function findangle0(z)
  return math.atan(z/2)
end

function main()
out(0,_VZ())
  if _KEY(14)>0 then if TRANSA==0
  then
    TRANSFLG=1
    TRANS1=0
    if TRANSB==90
    then
      ANGLE=0
    end
  end end
  if _KEY(15)>0 then if TRANSB==0
  then
    TRANSFLG=1
    TRANS1=1
    Y=_Y()+2.5
    AX=_AX()
    AY=_AY()
    AZ=_AZ()
    ANGLE=_AY()
    SPEED=_VZ()
    HOVER=0
    FRONT=0
    SIDE=0
    SPIN=0
  end end
  if _KEY(16)>0 then if TRANSC==0
  then
    TRANSFLG=1
    TRANS1=2
    if TRANSB==90
    then
      ANGLE=0
    end
  end end

  if TRANSB>0
  then
      LTILT=0
      RTILT=0
      LTHRUST=36000
      RTHRUST=36000

      if _H()<=1 then if Y<_Y()+2 then if _H()>=0
      then
          Y=_Y()-_H()+2
      end end end
--      Y=Y+absmax(_Y()-Y,100)
      DAX=mod(_AX()-AX)
      DAY=mod(_AY()-AY)
      DAZ=mod(_AZ()-AZ)
      AX=_AX()
      AY=_AY()
      AZ=_AZ()

      SPEED=SPEED+_VZ()*1000
      THRUST=SPEED+_VZ()*10000

      ANGLE=ANGLE-DAY*100000
      SPIN=5*ANGLE-DAY*10000000

      HOVER=(Y-_Y()-_VY())*-10000
      FRONT=(2*math.tan(1.1*absmax(_AX(),math.pi))+30*DAX)*5000-0.17*THRUST-0.1*HOVER
      SIDE=(2*math.tan(1.1*absmax(_AZ(),math.pi))+50*DAZ+_VX())*-10000

      NW=HOVER+FRONT+SIDE
      SW=HOVER-FRONT+SIDE
      SE=HOVER-FRONT-SIDE
      NE=HOVER+FRONT-SIDE
      LEFT=THRUST+SPIN
      RIGHT=THRUST-SPIN
  else
      NW=0
      SW=0
      SE=0
      NE=0
      LEFT=0
      RIGHT=-0
  end

  if TRANSC>0
  then
    TIME=mod(TIME+CRAWL)
    y=findy(0)
    z=findz(0)
    ANGLE02=findangle2(y,z)
    ANGLE01=findangle1(ANGLE02,y,z)
    ANGLE00=findangle0(z)
    y=findy(1)
    z=findz(1)
    ANGLE12=findangle2(y,z)
    ANGLE11=findangle1(ANGLE12,y,z)
    ANGLE10=findangle0(z)

    ANGLE00=ANGLE00*TRANSC*2/math.pi+180
    ANGLE01=ANGLE01*TRANSC*2/math.pi
    ANGLE02=ANGLE02*TRANSC*2/math.pi
    ANGLE10=ANGLE10*TRANSC*2/math.pi+180
    ANGLE11=ANGLE11*TRANSC*2/math.pi
    ANGLE12=ANGLE12*TRANSC*2/math.pi
    ANGLE21=ANGLE11-TRANSB
    ANGLE22=-ANGLE12+180
    ANGLE31=ANGLE01-TRANSB
    ANGLE32=-ANGLE02+180
    ANGLE23=TRANSC-90
    ANGLE33=TRANSC-90

    BRAKE=TRANSC*TRANSC+BRAKE0
  else
  ANGLE00=180
  ANGLE10=180
  ANGLE01=0
  ANGLE11=0
  ANGLE02=0
  ANGLE12=0
  ANGLE21=-TRANSB
  ANGLE31=-TRANSB
  ANGLE22=180
  ANGLE32=180
  ANGLE23=-90
  ANGLE33=-90
  end

  ENGINE=ENGINE0*TRANSA/90
  HANDLE=HANDLE0*(TRANSA+TRANSC)/90

  if TRANSFLG==0
  then
    if TRANSA==90 then TRANS0=0 end
    if TRANSB==90 then TRANS0=1 end
    if TRANSC==90 then TRANS0=2 end
  else
    if TRANS0==0
      then TRANSA=TRANSA-5 end
    if TRANS1==0
      then TRANSA=TRANSA+5 end
    if TRANS0==1
      then TRANSB=TRANSB-5 end
    if TRANS1==1
      then TRANSB=TRANSB+5 end
    if TRANS0==2
      then TRANSC=TRANSC-5 end
    if TRANS1==2
      then TRANSC=TRANSC+5 end
    if TRANSB<90
    then
      NW=NW*TRANSB*TRANSB/8100
      SW=SW*TRANSB*TRANSB/8100
      SE=SE*TRANSB*TRANSB/8100
      NE=NE*TRANSB*TRANSB/8100
      LEFT=LEFT*TRANSB*TRANSB/8100
      RIGHT=RIGHT*TRANSB*TRANSB/8100
    end
    if TRANSA>=90
    then
      TRANSA=90
      TRANSFLG=0
    end
    if TRANSB>=90
    then
      TRANSB=90
      TRANSFLG=0
    end
    if TRANSC>=90
    then
      TRANSC=90
      TRANSFLG=0
    end
    DAMP=(0.2*TRANSA+TRANSB+TRANSC)/90
  end
end
}


Last edited by DanielLC on Sat Nov 20, 2010 7:05 pm; edited 1 time in total

DanielLC
Tank
Tank

Posts : 78
Join date : 2010-10-23

View user profile

Back to top Go down

Re: Transformer

Post by JHaskly on Sat Oct 30, 2010 4:53 pm

Great model! I didn't know this was yours.

The only thing I have to suggest is perhaps make the jets less sensitive in hover mode (at least at low speeds), because it's doing a lot of bouncing around.

_________________
Previously (and currently) known as Juz.

Please do not write "LUA", beause it's "Lua". It's Moon in Portuguese, not a Limited User Account, Last Universal Ancestor, or the Lukla Airport in Nepal.

JHaskly
Admin

Posts : 235
Join date : 2010-07-16
Age : 21
Location : Brisbane

View user profile

Back to top Go down

Re: Transformer

Post by DanielLC on Sat Nov 20, 2010 7:07 pm

I found my problem. I was thinking it wasn't adjusting to the angle it should be quickly enough. It's just that it wasn't slowing down quickly enough.

I'm having some trouble with increasing and decreasing altitude (z and x).

DanielLC
Tank
Tank

Posts : 78
Join date : 2010-10-23

View user profile

Back to top Go down

Re: Transformer

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum