From c68ee69c9b8a885e5e58a759e96e831b1e8ce973 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 21 Apr 2021 21:30:48 -0500 Subject: [PATCH] Document raycasting --- core/World.h | 9 +++++++++ demo/shooter/main.lua | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/World.h b/core/World.h index cb95d5d..74083f5 100644 --- a/core/World.h +++ b/core/World.h @@ -27,6 +27,9 @@ #include "Rigidbody.h" +/** + Holds information about the results of a raycast +*/ struct RaycastResult { bool hit; Vector3 position; @@ -54,6 +57,12 @@ public: */ void Step(float delta); + /** + Performs a raycast + @param from the start location of the raycast + @param to the end location of the raycast + @returns a RaycastResult with data collected by the raycast + */ RaycastResult Raycast(const Vector3 &from, const Vector3 &to); private: static World* world; diff --git a/demo/shooter/main.lua b/demo/shooter/main.lua index 6fce558..c3bbaf9 100644 --- a/demo/shooter/main.lua +++ b/demo/shooter/main.lua @@ -37,7 +37,7 @@ function onkey(key, code, action, mod) local res = couch.World.GetWorld():Raycast(camera_transform.position, camera_transform.position + camera_transform:Forward() * 100.0) if (res.hit) then - res.object:ApplyImpulse(res.normal * -100.0) + res.object:ApplyImpulse(camera_transform:Forward() * 100.0) end end end