Instantly share code, notes, and snippets.

Embed
What would you like to do?
(ns game.core
(:use
arcadia.core
arcadia.linear
tween.core
hard.core
hard.input))
(def orbit-height 2.0)
(defn from-to-rotation [from to]
(UnityEngine.Quaternion/FromToRotation from to))
(defn planet? [o]
(re-find #"planet" (.name o)))
(defn ship-keys [o]
(cond
(key? "a") (rotate! (the rotatoe) (v3 0 -1 0))
(key? "d") (rotate! (the rotatoe) (v3 0 1 0))))
(defn update-ship [o]
(ship-keys o)
(position! o (v3+ (->v3 o) (local-direction (the rotatoe) (v3 0.1 0 0)))))
(defn gizmos-ship [o]
(gizmo-color (color 1 0 0))
(gizmo-ray (->v3 o) (local-direction o (v3 0 -10 0)))
(let [ray (Ray. (->v3 o) (local-direction o (v3 0 -1 0)))
hits (ray-hits ray)
hit (first (filter #(planet? (->go (.collider %))) hits))]
(when hit
(let [norm-ray (Ray. (.point hit) (.normal hit))
orbit-point (.GetPoint norm-ray orbit-height)
norm-quat (from-to-rotation
(local-direction o (Vector3/up))
(.normal hit))
fwd (local-direction o (v3 1 0 0))
good-quat (Quaternion/LookRotation (.normal hit) fwd )]
(gizmo-color (color 0 1 1))
(gizmo-point (.point hit) 0.5)
(gizmo-ray (.point hit) (.normal hit))
(gizmo-ray (->v3 o) (local-direction (the rotatoe) (v3 5 0 0)))
(gizmo-color (color 1 0 1))
(gizmo-point orbit-point 0.2)
(set! (.rotation (.transform o))
(from-to-rotation (Vector3/up) (.normal hit))
)
(ship-keys o)
(position! o orbit-point)
))))
(defn make-level []
(clear-cloned!)
(let [p (clone! :planet2)
spawn (first (children p))
s (clone! :ship (->v3 spawn))]
(dorun (for [i (range 60)]
(clone! :Sphere (?on-sphere 10.0))))
(hook+ s :update update-ship)
(hook+ s :on-draw-gizmos gizmos-ship)))
(make-level)
@selfsame

This comment has been minimized.

Owner

selfsame commented Aug 4, 2016

lisp3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment