CannonRaycastVehicle.re.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import * as RE from 'rogue-engine';
  2. import * as THREE from 'three';
  3. import * as CANNON from 'cannon-es';
  4. import CannonBody from '../CannonBody.re';
  5. import * as RogueCannon from '../../Lib/RogueCannon';
  6. export default class CannonRaycastVehicle extends RE.Component {
  7. @RE.props.object3d() chasis: THREE.Object3D;
  8. @RE.props.num() mass = 500;
  9. @RE.props.num() suspensionStiffness = 30;
  10. @RE.props.num() suspensionRestLength = 0.1;
  11. @RE.props.num() frictionSlip = 0.7;
  12. @RE.props.num() dampingRelaxation: 2.3;
  13. @RE.props.num() dampingCompression: 4.4;
  14. @RE.props.num() maxSuspensionForce: 100000;
  15. @RE.props.num() rollInfluence: 0.01;
  16. @RE.props.num() maxSuspensionTravel = 0.2;
  17. @RE.props.num() customSlidingRotationalSpeed = -30;
  18. @RE.props.checkbox() useCustomSlidingRotationalSpeed = true;
  19. vehicle: CANNON.RaycastVehicle;
  20. start() {
  21. if (!RogueCannon.getWorld()) return;
  22. let body = RE.getComponent(CannonBody, this.object3d);
  23. if (!body) {
  24. body = new CannonBody("CarBody", this.object3d);
  25. body.mass = this.mass;
  26. RE.addComponent(body);
  27. }
  28. if (!this.chasis) return;
  29. const chassisBody = RE.getComponent(CannonBody, this.chasis);
  30. if (!(chassisBody instanceof CannonBody)) return;
  31. this.vehicle = new CANNON.RaycastVehicle({
  32. chassisBody: body.body,
  33. indexForwardAxis: 2,
  34. indexUpAxis: 1,
  35. indexRightAxis: 0,
  36. });
  37. this.vehicle.addToWorld(RogueCannon.getWorld());
  38. }
  39. }
  40. RE.registerComponent(CannonRaycastVehicle);