I am trying a simple project in playcanvas react where a sphere falls into a big ground plane just to test the physics.
As it seems, the half extents prop does not do anything because the “collision model” of the box might continue to be 1x1x1.
Am i doing something wrong with this code?
import React from 'react';
import { Application, Entity } from '@playcanvas/react';
import { Camera, Render, Light, Collision, RigidBody } from '@playcanvas/react/components';
import { OrbitControls } from '@playcanvas/react/scripts';
import { FILLMODE_FILL_WINDOW, RESOLUTION_AUTO } from 'playcanvas';
import { usePhysics } from '@playcanvas/react/hooks';
const PhysicsScene = () => {
const { isPhysicsLoaded } = usePhysics();
if (!isPhysicsLoaded) {
return null;
}
// En lugar de un fragmento <>, usamos una <Entity> como contenedor principal.
return (
<Entity name="PhysicsRoot">
{/* Ground Plane */}
<Entity name='ground'>
<Entity scale={[20, 1, 20]}>
<Render type="box" />
</Entity>
<Collision type="box" halfExtents={[10, 0.5, 10]} />
<RigidBody type="static" />
</Entity>
{/* Falling Sphere (Ahora respetará su posición inicial) */}
<Entity name='fallingSphere' position={[0, 15, 0.5]}>
<Render type="sphere" />
<Collision type="sphere" radius={1} />
<RigidBody type="dynamic" mass={50} />
</Entity>
</Entity>
);
};
export default function App() {
return (
<Application
fillMode={FILLMODE_FILL_WINDOW}
resolutionMode={RESOLUTION_AUTO}
usePhysics
>
<Entity name='camera' position={[0, 10, 25]}>
<Camera />
<OrbitControls />
</Entity>
<Entity name='light' rotation={[45, -45, 45]}>
<Light type='directional' />
</Entity>
<PhysicsScene />
</Application>
);
}
Thanks in advance!