Skip to content

Instantly share code, notes, and snippets.

@timsgardner
Created April 2, 2017 20:52
Show Gist options
  • Save timsgardner/d5fb03ed17e6007bdbb6c3336b321b88 to your computer and use it in GitHub Desktop.
Save timsgardner/d5fb03ed17e6007bdbb6c3336b321b88 to your computer and use it in GitHub Desktop.
thing
(defn go-to [^UnityEngine.GameObject obj]
(when-let [^UnityEngine.GameObject target (state obj ::target)]
(let [max-accel (float (or (state obj ::max-accel)
(throw
(Exception.
"Expects :car-scene.movement/max-accel key in state"))))]
(with-cmpt target [targ-tr UnityEngine.Transform]
(with-cmpt obj [tr UnityEngine.Transform
rb UnityEngine.Rigidbody]
(let [^UnityEngine.Transform targ-tr (.GetComponent target UnityEngine.Transform)
^UnityEngine.Transform tr (.GetComponent obj UnityEngine.Transform)
^UnityEngine.Rigidbody rb (.GetComponent obj UnityEngine.Rigidbody)]
(mf/faster
:hi
;; (let [vel (.velocity rb)
;; difvec (v3- (.position targ-tr) (.position tr))
;; pos (.position tr)
;; targ-pos (.position targ-tr)]
;; ; if it's too close just stop
;; (if (or (< 0.001 (UnityEngine.Mathf/Abs (UnityEngine.Vector3/Magnitude vel)))
;; (< 0.001 (UnityEngine.Vector3/Distance pos targ-pos)))
;; (let [force-vec
;; ;; (lookahead-acc pos targ-pos vel max-accel)
;; (barrel-towards pos, targ-pos, max-accel)
;; ;; (lookahead-cinematic pos targ-pos vel max-accel)
;; ]
;; (.AddForce rb force-vec UnityEngine.ForceMode/Acceleration)
;; )
;; (do ;; (set-state! obj ::show-vectors nil)
;; (sets! rb velocity (v3 0))))
;; )
)
))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment