Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns game.core
(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]
(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 []
(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)))

This comment has been minimized.

Copy link
Owner Author

commented Aug 4, 2016


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.