Ajustar parámetros de fricción estática y dinámica en la simulación de botellas, mejorando el comportamiento en situaciones de contacto. Implementar límites de velocidad en el plano XY y corregir la lógica de actualización de posición para evitar elevaciones excesivas.

This commit is contained in:
Miguel 2025-09-02 12:30:30 +02:00
parent 18017db56a
commit 3b953b7998
1 changed files with 22 additions and 9 deletions

View File

@ -340,8 +340,8 @@ namespace CtrEditor.Simulacion
float slipSpeedThreshold = transportVelocity.Length()*0.85f; // m/s - umbral para cambiar de fricción estática a dinámica float slipSpeedThreshold = transportVelocity.Length()*0.85f; // m/s - umbral para cambiar de fricción estática a dinámica
const float heatupRate = 1f; // Qué tan rápido sube HighSlippery const float heatupRate = 1f; // Qué tan rápido sube HighSlippery
const float cooldownRate = 1f; // Qué tan rápido baja HighSlippery const float cooldownRate = 1f; // Qué tan rápido baja HighSlippery
const float staticFriction = 0.80f; const float staticFriction = 0.50f;
const float dynamicFriction = 0.50f; const float dynamicFriction = 0.30f;
// Sistema de heatup/cooldown para HighSlippery // Sistema de heatup/cooldown para HighSlippery
if (slipSpeed > slipSpeedThreshold) // && botella.ContactPressure > 0 if (slipSpeed > slipSpeedThreshold) // && botella.ContactPressure > 0
@ -396,8 +396,8 @@ namespace CtrEditor.Simulacion
float slipSpeedThreshold = curveVelocityAtPoint.Length() * 0.85f; // m/s float slipSpeedThreshold = curveVelocityAtPoint.Length() * 0.85f; // m/s
const float heatupRate = 1f; // Qué tan rápido sube HighSlippery en curvas const float heatupRate = 1f; // Qué tan rápido sube HighSlippery en curvas
const float cooldownRate = 1f; // Qué tan rápido baja HighSlippery en curvas const float cooldownRate = 1f; // Qué tan rápido baja HighSlippery en curvas
const float staticFriction = 0.80f; const float staticFriction = 0.50f;
const float dynamicFriction = 0.50f; const float dynamicFriction = 0.30f;
// Sistema de heatup/cooldown para HighSlippery // Sistema de heatup/cooldown para HighSlippery
if (slipSpeed > slipSpeedThreshold) // && botella.ContactPressure > 0 if (slipSpeed > slipSpeedThreshold) // && botella.ContactPressure > 0
@ -411,7 +411,7 @@ namespace CtrEditor.Simulacion
return dynamicFriction / 10; return dynamicFriction / 10;
else else
{ {
if (botella.HighSlippery > 3f) if (botella.HighSlippery > 1f)
return dynamicFriction; return dynamicFriction;
else else
return staticFriction; return staticFriction;
@ -828,21 +828,34 @@ namespace CtrEditor.Simulacion
{ {
var body = simulation.Bodies.GetBodyReference(botella.BodyHandle); var body = simulation.Bodies.GetBodyReference(botella.BodyHandle);
var velocity = body.Velocity; var velocity = body.Velocity;
var position = body.Pose.Position; var pose = body.Pose;
// CONFIGURACIÓN DE LÍMITES // CONFIGURACIÓN DE LÍMITES
const float maxUpwardVelocity = 0f; // Velocidad Z máxima hacia arriba (m/s) const float maxUpwardVelocity = 0f; // Velocidad Z máxima hacia arriba (m/s)
const float maxXYVelocity = 1.0f; // Límite de velocidad en el plano XY (m/s)
// LIMITAR VELOCIDADES Z EXCESIVAS // LIMITAR VELOCIDADES Z EXCESIVAS
if (velocity.Linear.Z > maxUpwardVelocity) if (velocity.Linear.Z > maxUpwardVelocity)
{ {
// Cancelar velocidades hacia arriba excesivas (anti-elevación) // Cancelar velocidades hacia arriba excesivas (anti-elevación)
velocity.Linear.Z = 0; velocity.Linear.Z = 0;
position.Z = botella.Radius + simBase.zPos_Transporte + simBase.zAltura_Transporte; pose.Position.Z = botella.Radius + simBase.zPos_Transporte + simBase.zAltura_Transporte;
body.Velocity = velocity; body.Pose = pose; // Se actualiza la pose completa
body.Pose = position;
} }
// LIMITAR VELOCIDAD MÁXIMA EN PLANO XY
var velocityXY = new Vector2(velocity.Linear.X, velocity.Linear.Y);
if (velocityXY.LengthSquared() > maxXYVelocity * maxXYVelocity)
{
var speedXY = velocityXY.Length();
var scale = maxXYVelocity / speedXY;
velocity.Linear.X *= scale;
velocity.Linear.Y *= scale;
}
// Aplicar siempre la velocidad, ya que puede haber sido modificada en Z o XY
body.Velocity = velocity;
//// CONTROL DE POSICIÓN EXTREMA //// CONTROL DE POSICIÓN EXTREMA
//// Si la botella está muy por encima del nivel normal, aplicar corrección //// Si la botella está muy por encima del nivel normal, aplicar corrección
//var maxAllowedZ = simBase.zPos_Transporte + simBase.zAltura_Transporte + botella.Radius * 2; //var maxAllowedZ = simBase.zPos_Transporte + simBase.zAltura_Transporte + botella.Radius * 2;