File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,24 @@ public void update(double dt) {
4747 acc .y = 0.0d ;
4848 acc .z = 0.0d ;
4949 }
50+
51+ public void applyGround (double dt , double height , Vector3f normal ) {
52+ if (pos .y < height ) {
53+ Vector3f v = new Vector3f ((float ) (pos .x - prevPos .x ), (float ) (pos .y - prevPos .y ), (float ) (pos .z - prevPos .z ));
54+ double diff = height - pos .y ;
55+ Vector3f resolve = Vector3f .mul (normal , (float ) diff );
56+ pos .x += resolve .x ;
57+ pos .y += resolve .y ;
58+ pos .z += resolve .z ;
59+ if (Vector3f .dot (v , normal ) > 0.0f ) {
60+ return ;
61+ }
62+ Vector3f vel = bounce (v , normal );
63+ prevPos .x = pos .x - vel .x ;
64+ prevPos .y = pos .y - vel .y ;
65+ prevPos .z = pos .z - vel .z ;
66+ }
67+ }
5068
5169 protected Vector3f bounce (Vector3f v , Vector3f n ) {
5270 float height = -Vector3f .dot (v , n );
You can’t perform that action at this time.
0 commit comments