Skip to content

Instantly share code, notes, and snippets.

@selfsame
Created October 10, 2014 16:51
Show Gist options
  • Save selfsame/5796e477b8844130d4dd to your computer and use it in GitHub Desktop.
Save selfsame/5796e477b8844130d4dd to your computer and use it in GitHub Desktop.
squid.clj
(ns biology.squid
(:use hard.core hard.input hard.tween unity.messages)
(:require unity.core))
(defn squid-start [this])
(defn squid-update [this]
(let [h (get-axis :horizontal)
v (get-axis :vertical)
body (component this "Rigidbody")
tail (find-name "squid|t.017")]
(when (key? "space") (.AddRelativeForce body -200 0 0))
(.AddRelativeTorque body (* h 100) 0 (* v 100))))
(defn get-tent [suffix]
(mapv find-name
(mapv #(str "squid|" % suffix)
["t" "a" "b" "c" "d" "e" "f" "g" "h" "i"])))
(def tcaplens [0.5 1.5 1.55 1.55 1.55 1.55 1.5 1.45 1.45 1.45])
(defn rig-squid []
(let [squid (clone! (resource "squid"))]
(mapv (fn [suf]
(let [tentvec (get-tent suf)]
(map-indexed
(fn [idx gob]
(let [capcol (.AddComponent gob UnityEngine.CapsuleCollider)
body (.AddComponent gob UnityEngine.Rigidbody)
]
(set! (.center capcol) (vec3 [0 0.5 0]))
(set! (.radius capcol) (float (- 0.25 (* idx 0.01))))
(set! (.height capcol) (float (get tcaplens idx)))
(set! (.mass body) (float (- 0.06 (* idx 0.002))))
(set! (.drag body)(float 0.5))
(set! (.angularDrag body) (float 0.5))
(set! (.useGravity body) false)
(let [joint (.AddComponent gob UnityEngine.HingeJoint)
limits (JointLimits. )
ts (-v + (-v * (-v - (vec3 squid) (vec3 gob)) [0 1 1]))
lra (StringGroup/rotateVector3 (vec3 ts) (Quaternion/AngleAxis 90 (vec3 [0 0 1])))
localaxis (.InverseTransformDirection (.transform gob) (vec3 lra))
lmin (float (+ (* -3 idx) -15))
lmax (float (+ (* 3 idx) 15))
]
(set! (.axis joint) lra)
(set! (.useLimits joint) true)
(set! (.min limits) lmin)
(set! (.max limits) lmax)
(set! (.limits joint) limits)
(set! (.connectedBody joint) (component (get (vec (cons squid tentvec)) idx) "Rigidbody")))))
tentvec)))
[".001" ".002" ".003" ".004" ".005" ".006" ".007" ".008" ])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment