Lua experiments: Stick figure

HXCTCreations - Custom level - from Android
PlayEdit7 players liked this.Log in to like this level.

Something I'm working on... It's still in early stage of work in progress and needs some transitions, but for now here it is.

Views: 504 Downloads: 167 Unique objects: 1 Total objects: 8

Discuss this level

Log in to comment on this level.
  • QuickestW0LF: Can't wait to see what comes from this...
  • TheBossMan: It looks better with an head
  • HXCTCreations: @Atomic Cyclone: I know.. I'm planning to include this in my next projects but I want it to do some complex motions first.
  • Atomic Cyclone: @HXCTCreations: demon666 made something similiare some time ago
  • Banget: Code for Lua Animation:
    --[[Custom Character]]--
    --[[Written by HXCT]]--
    function init(is_sandbox)
    this:set_draw_z(1)
    this:set_draw_tint(1,1,0,1)
    stand=0
    walk=0
    jump=0
    spd=1/200

    char={
    rootx=0,rooty=0,
    body=1,ba=0,
    neck=0.4,bn=0,
    leg1u=1,leg1d=1,
    leg2u=1,leg2d=1,
    arm1u=0.6,arm1d=0.6,
    arm2u=0.6,arm2d=0.6,
    ratio=0.05,ik={}
    }

    end

    function step(count)
    if this:read(0)==1 then
    walk_anim()
    else
    stand_anim()
    end
    proc_ik()
    render_skeleton()
    end

    function stand_anim()
    walk,jump=0,0
    stand=(stand+spd/2)%1
    char.rx,char.ry=char.rootx+math.sin(stand*math.pi*2)*char.ratio,char.rooty--+math.sin(stand*math.pi*2)*char.ratio
    char.ik.leg1x,char.ik.leg1y=char.rootx+0.1,char.rooty-char.leg1u-char.leg1d
    char.ik.leg2x,char.ik.leg2y=char.rootx-0.1,char.rooty-char.leg2u-char.leg2d
    char.ik.arm1x,char.ik.arm1y=char.rootx-0.1,char.rooty+char.body-char.arm1u-char.arm1d+0.02
    char.ik.arm2x,char.ik.arm2y=char.rootx+0.1,char.rooty+char.body-char.arm2u-char.arm2d+0.02
    end

    function walk_anim()
    stand,jump=0,0
    walk=(walk+spd)%1
    char.rx,char.ry=char.rootx,char.rooty+math.sin(walk*math.pi*4+math.pi/2)*char.ratio-char.ratio
    char.ik.leg1x,char.ik.leg1y=char.rootx+0.5*math.sin(walk*math.pi*2),char.rooty-char.leg1u-char.leg1d+0.1*math.cos(walk*math.pi*2)
    char.ik.leg2x,char.ik.leg2y=char.rootx-0.5*math.sin(walk*math.pi*2),char.rooty-char.leg2u-char.leg2d-0.1*math.cos(walk*math.pi*2)
    char.ik.arm1x,char.ik.arm1y=char.rootx-0.5*math.sin(walk*math.pi*2),char.rooty+char.body-char.arm1u-char.arm1d-0.05*math.sin(walk*math.pi*2)
    char.ik.arm2x,char.ik.arm2y=char.rootx+0.5*math.sin(walk*math.pi*2),char.rooty+char.body-char.arm2u-char.arm2d+0.05*math.sin(walk*math.pi*2)

    end

    function jump_anim()
    end



    function proc_ik()
    char.aleg1u,char.aleg1d=apply_ik(char.rx,char.ry,char.leg1u,char.leg1d,char.ik.leg1x,char.ik.leg1y,-1)
    char.aleg2u,char.aleg2d=apply_ik(char.rx,char.ry,char.leg2u,char.leg2d,char.ik.leg2x,char.ik.leg2y,-1)
    char.aarm1u,char.aarm1d=apply_ik(char.rx,char.ry+char.body,char.arm1u,char.arm1d,char.ik.arm1x,char.ik.arm1y,1)
    char.aarm2u,char.aarm2d=apply_ik(char.rx,char.ry+char.body,char.arm2u,char.arm2d,char.ik.arm2x,char.ik.arm2y,1)
    end

    function render_skeleton()
    local ax,ay=char.leg1u*math.cos(char.aleg1u),char.leg1u*math.sin(char.aleg1u)
    local bx,by=char.leg1d*math.cos(char.aleg1d),char.leg1d*math.sin(char.aleg1d)
    local cx,cy=char.leg2u*math.cos(char.aleg2u),char.leg2u*math.sin(char.aleg2u)
    local dx,dy=char.leg2d*math.cos(char.aleg2d),char.leg2d*math.sin(char.aleg2d)
    local ex,ey=char.arm1u*math.cos(char.aarm1u),char.arm1u*math.sin(char.aarm1u)
    local fx,fy=char.arm1d*math.cos(char.aarm1d),char.arm1d*math.sin(char.aarm1d)
    local gx,gy=char.arm2u*math.cos(char.aarm2u),char.arm2u*math.sin(char.aarm2u)
    local hx,hy=char.arm2d*math.cos(char.aarm2d),char.arm2d*math.sin(char.aarm2d)
    --left arm
    this:draw_line(char.rx,char.ry+char.body,char.rx+gx,char.ry+char.body+gy,0.05)
    this:draw_line(char.rx+gx,char.ry+char.body+gy,char.rx+gx+hx,char.ry+char.body+gy+hy,0.05)
    --left leg
    this:draw_line(char.rx,char.ry,char.rx+cx,char.ry+cy,0.05)
    this:draw_line(char.rx+cx,char.ry+cy,char.rx+cx+dx,char.ry+cy+dy,0.05)
    --body
    this:draw_line(char.rx,char.ry,char.rx,char.ry+char.body,0.05)
    this:draw_line(char.rx,char.ry+char.body,char.rx,char.ry+char.body+char.neck,0.05)
    --right arm
    this:draw_line(char.rx,char.ry+char.body,char.rx+ex,char.ry+char.body+ey,0.05)
    this:draw_line(char.rx+ex,char.ry+char.body+ey,char.rx+ex+fx,char.ry+char.body+ey+fy,0.05)
    --right leg
    this:draw_line(char.rx,char.ry,char.rx+ax,char.ry+ay,0.05)
    this:draw_line(char.rx+ax,char.ry+ay,char.rx+ax+bx,char.ry+ay+by,0.05)

    --this:draw_sprite(char.ik.arm1x,char.ik.arm1y,0,0.1,0.1,0,0,0,0)
    --game:message(char.aarm1u.." "..char.aarm1d)
    end

    function apply_ik(pivotx,pivoty,arm1,arm2,targetx,targety,dir)
    ang=math.atan2(targety-pivoty,targetx-pivotx)
    dist=math.sqrt((targetx-pivotx)^2+(targety-pivoty)^2)
    if dist>=arm1+arm2 then
    pole_ang=0
    arm_ang=0
    else
    pole_ang=math.acos((dist^2-arm1^2-arm2^2)/(2*arm1*arm2))
    arm_ang=((math.acos((arm2^2-arm1^2-dist^2)/(2*arm1*dist))+math.pi)%(math.pi*2))
    end
    return ang+(arm_ang)*dir,ang+(arm_ang+pole_ang)*dir
    end

    function mod(x,y)
    r=math.floor(x/y)
    return x-r*y
    end
  • x32g: I don't know anything about lua, so I don't know how hard this would be, but I recommend you make it shorter. It looks kinda creepy all thin and sticklike. (Yes, that is the definition of a stick figure)
  • TheBossMan: Make it so he can run too
  • TechZ2124: Nice !
  • JOELwindows7: This animation is really complex! Duper Awesome
  • Hobbit: Very realistic movement, can't wait to see what you come up with.
  • HXCTCreations: @Egorik: he has no head.. unfortunately
  • Egorik: Where head

LEVEL ID: 24865