Advertisement
onexiv

Collision Checking (unfinished)

Oct 23rd, 2023
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  2. check() {
  3. this.segments.forEach(element => {
  4. this.detect(element.position);
  5. });
  6. }
  7.  
  8. detect(elem) {
  9. // Speed might jump the distanceThreshold ** CAUTION **
  10. this.hid.speed = 5;
  11. var moveSpeed = this.hid.speed;
  12. var norbitA = (Math.abs(this.camera.position.x)) ?? -1;
  13. var norbitB = (Math.abs(this.camera.position.z)) ?? -1;
  14. var x = this.hid.direction.x;
  15. var z = this.hid.direction.z;
  16. var positive = ((this.hid.moveForward || this.hid.moveRight) > (this.hid.moveBackward || this.hid.moveLeft)) * (-1);
  17. // 1 for either direction
  18. var d = (x > z) ?? z * (-norbitA);
  19. var cam = this.camera.position;
  20. // find hyperbolic in condition
  21.  
  22. console.log((d * moveSpeed) * positive * (-norbitB));
  23. this.hid.controls.moveRight((d * moveSpeed) * positive * (-norbitB));
  24. this.hid.controls.moveForward((d * moveSpeed) * positive * (-norbitB));
  25. const delta = this.hid.clock.getDelta();
  26. this.hid.update(delta);
  27. if (cam.x === (elem.x | elem.z) || cam.z === (elem.x | elem.z)) {
  28. this.hid.controls.moveRight((d * moveSpeed) * positive * (norbitB));
  29. this.hid.controls.moveForward((d * moveSpeed) * positive * (norbitB));
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement