Hello everyone,
I am currently working on a car simulator that utilizes dynamic lights, as demonstrated in this video: Dynamic Lights Car Simulator. However, I also have a version without dynamic lights, where all the lights have fixed positions and rotations: Fixed Position Lights Car Simulator.
This simulator is based on the Neon Racer Car Simulator.
I am seeking advice on performance optimization for the dynamic lighting implementation, particularly with the lights being part of the rigid body. Additionally, I’ve noticed that the camera occasionally lags behind due to FPS drops during gameplay.
Any tips or strategies to improve performance and camera responsiveness would be greatly appreciated!
return (
<>
<group>
<RigidBody
softCcdPrediction={50}
collisionGroups={collisionGroups.OWN}
solverGroups={collisionGroups.OWN}
friction={0.1}
onIntersectionEnter={(e) => {
if (e.collider) {
// Eğer yere değiyorsa driftContact.current = true olur
const isGround = e.collider; // e.collider ile temas edilen nesneyi kontrol et
driftContact.current = isGround ? true : false;
}
}}
onIntersectionExit={() => {
// Yerden ayrılınca driftContact.current = false
driftContact.current = false;
}}
name='car'
position={[position[0],position[1],position[2]]}
rotation={rotation}
canSleep={false}
ref={chasisBodyRef}
colliders={false}
type="dynamic"
scale={scaleOfCar}
angularDamping={angularDamping}
>
<group ref={allBody} scale={[1,1,1.25]}>
{
//burası 0.5 arttı
}
<CuboidCollider collisionGroups={collisionGroups.BODY}
mass={0.1} position={[0,0.45,0]} args={[0.8, 0.4, 0.4]} />
<CuboidCollider collisionGroups={collisionGroups.BODY}
mass={2} position={[1.4,0.35,0]} args={[0.2, 0.2, 0.4]} />
<group>
{
!Nitro && nitroForce == 100 && <ModelForAnimsPrimitive url={Nitro} meshArgs={{position: [0,0,0], rotation: [0,0,-Math.PI / 2], scale: [0.01,5,0.25]}} BodyArgs={{colliders:false}} controller={false} myIndex={999} />
}
<CuboidCollider collisionGroups={collisionGroups.BODY}
mass={1} position={[-1.4,0.35,0]} args={[0.2, 0.2, 0.4]} />
</group>
</group>
{/* chassis */}
{/* chassis */}
{/* chassis */}
<group visible rotation={[0, -Math.PI / 2, 0]} ref={chasisMeshRef} scale={0.6}>
{
type === "GLB" && CarFBX && <primitive key={Math.random() * 1000} ref={carRef} object={CarFBX} />
}
{type === "FBX" && body.current && body.current.length > 0 && body.current.map((mesh, index) => (
<mesh key={"car_racer" + index}>
<primitive ref={carRef} object={mesh} />
</mesh>
))}
</group>
{/* wheels */}
{wheelsRef.current && wheels.map((wheel, index) => (
<group key={index} ref={(ref) => ((wheelsRef.current)[index] = ref)} position={wheel.position}>
<group scale={[1,1,1]} rotation-x={-Math.PI / 2}>
<mesh position={[0,0,0]}>
<cylinderGeometry collisionGroups={collisionGroups.WHEELS} args={[0.25, 0.25, 0.225, 64]} />
<meshStandardMaterial map={_wheelTexture}/>
</mesh>
<mesh position={[0,0,0]}>
<cylinderGeometry collisionGroups={collisionGroups.WHEELS} args={[0.25, 0.25, 0.225, 64]} />
<meshStandardMaterial map={_wheelTexture} />
</mesh>
</group>
</group>
))}
<pointLight
ref={pointLightRef}
color={"white"}
intensity={2} // Şiddeti düşürdük
position={[-5, 3, 0]} // Başlangıç pozisyonu
distance={50} // Mesafeyi artırdık
angle={Math.PI / 2} // Açıyı pozitif yaptık
penumbra={0.2}
decay={0.1} // Dağılma faktörünü artırdık
castShadow
shadow-mapSize-width={256}
shadow-mapSize-height={256}
shadow-near={0.5}
shadow-far={50}
/>
</RigidBody>
</group>
{MemoizedPlayerList}
</>
)