/// <summary> /// 计算速度衰减 /// </summary> /// <param name="areaType"></param> /// <param name="velocity"></param> /// <param name="normal"></param> /// <returns></returns> public Vector3 CalcVelocityDecay(AreaType areaType, Vector3 velocity, Vector3 normal, bool isDecay) { if (isDecay) { GroundmaterialConfig groundMatConfig = GroundmaterialDao.Inst.GetCfg((uint)areaType); if (groundMatConfig == null) { return(Vector3.zero); } //衰减斜率 float k = (float)groundMatConfig.DecreaseSlope; //衰减起始值 float offset = (float)groundMatConfig.DecreaseBias; //入射速度在法线上的投影,该投影与衰减值呈k为斜率和offset为起始值的线性关系 float p = Vector3.Dot(-velocity, normal); float decay = (k * p + offset) / 100; //衰减不能放大,范围0-1 decay = Mathf.Clamp01(decay); Vector3 decayVelocity = velocity * (1 - decay); //Debug.Log("衰减斜率:" + k + " 衰减偏移:" + offset + "速度法线投影:" + p + " 衰减:" + decay + " 速度:" + decayVelocity + " 开始速度:" + velocity); return(decayVelocity); } return(velocity); }
/// <summary> /// 计算滚动点的摩擦力加速度 /// </summary> /// <param name="velocity"></param> /// <param name="areaType"></param> /// <returns></returns> public Vector3 CalcRollFrictionAcc(Vector3 velocity, AreaType areaType, GolfAIMapPolygon poly) { GroundmaterialConfig groundMatConfig = GroundmaterialDao.Inst.GetCfg((uint)areaType); if (groundMatConfig == null) { return(Vector3.zero); } //摩擦系数 float u = groundMatConfig.Friction; //获取小球在该三角面的加速度 Vector3 acc = poly.GetAcceleration(velocity, 1, u); return(acc); }
public GolfPath(GolfCourseMap map) { m_CurMap = map; MotionPath = new GolfMotionPath(map); SpinDic = new Dictionary <int, List <float> >(); //旋球临时数据 for (int j = 0; j < 4; j++) { List <float> spinList = new List <float>(); spinList.Clear(); for (int i = 1; i <= 5; i++) { GroundmaterialConfig groundMatConfig = GroundmaterialDao.Inst.GetCfg((uint)i); spinList.Add(groundMatConfig.SpinAddition1); } SpinDic.Add(j, spinList); } }
/// <summary> /// 检查是否可以反弹 /// </summary> /// <param name="velocity"></param> /// <param name="normal"></param> /// <param name="areaType"></param> /// <returns></returns> public bool CheckCanBounce(Vector3 velocity, Vector3 normal, AreaType areaType, int haveReboundCount) { if (haveReboundCount >= 3) { return(false); } GroundmaterialConfig groundMatConfig = GroundmaterialDao.Inst.GetCfg((uint)areaType); if (groundMatConfig == null) { return(false); } float minBounceVelocity = (float)groundMatConfig.MinBounceVelocity / 100.0f; float p = Mathf.Abs(Vector3.Dot(-velocity, normal)); if (p >= minBounceVelocity) { return(true); } return(false); }