diff --git a/client/client.lua b/client/client.lua index f5e49a9..6377262 100644 --- a/client/client.lua +++ b/client/client.lua @@ -24,6 +24,9 @@ local function norm(vec) return vec end +-- Per-ped smoothed Z, keyed by ped entity handle +local smoothedZ = {} + local function applyScaleToEntity(ped, scale) local forward, right, upVector, position = GetEntityMatrix(ped) @@ -31,20 +34,57 @@ local function applyScaleToEntity(ped, scale) local rightNorm = norm(right) * scale local upNorm = norm(upVector) * scale - local zOffset = (1.0 - scale) * 1.0 * 0.5 - local adjustedZ = position.z - zOffset + -- Only look ahead when moving up, cast straight down when descending + local vel = GetEntityVelocity(ped) + local isMovingUp = vel.z > 0.1 + local lookAhead = isMovingUp and 0.3 or 0.0 - if GetEntitySpeed(ped) > 0 then - adjustedZ = adjustedZ - zOffset + local rayStart = vector3(position.x + vel.x * lookAhead, position.y + vel.y * lookAhead, position.z + 2.0) + local rayEnd = vector3(position.x + vel.x * lookAhead, position.y + vel.y * lookAhead, position.z - 2.5) + local ray = StartShapeTestRay(rayStart.x, rayStart.y, rayStart.z, rayEnd.x, rayEnd.y, rayEnd.z, 1 | 16, ped, 0) + local _, hit, groundPos = GetShapeTestResult(ray) + + -- Fallback: straight down with longer range for flat ground / last step + if hit ~= 1 then + local rayStart2 = vector3(position.x, position.y, position.z + 2.0) + local rayEnd2 = vector3(position.x, position.y, position.z - 5.0) + local ray2 = StartShapeTestRay(rayStart2.x, rayStart2.y, rayStart2.z, rayEnd2.x, rayEnd2.y, rayEnd2.z, 1 | 16, ped, 0) + _, hit, groundPos = GetShapeTestResult(ray2) + end + + local groundZ + if hit == 1 then + groundZ = groundPos.z else - adjustedZ = adjustedZ + zOffset + local found, gz = GetGroundZFor_3dCoord(position.x, position.y, position.z, false) + groundZ = found and gz or position.z + end + + local targetZ = groundZ + scale + 0.04 + + local pedKey = tostring(ped) + if smoothedZ[pedKey] == nil then + smoothedZ[pedKey] = targetZ + end + + if targetZ > smoothedZ[pedKey] then + -- Going up: snap for large steps, lerp for small ones + local diff = targetZ - smoothedZ[pedKey] + if diff > 0.3 then + smoothedZ[pedKey] = targetZ + else + smoothedZ[pedKey] = smoothedZ[pedKey] + diff * 0.3 + end + else + -- Going down: always lerp smoothly + smoothedZ[pedKey] = smoothedZ[pedKey] + (targetZ - smoothedZ[pedKey]) * 0.18 end SetEntityMatrix(ped, forwardNorm.x, forwardNorm.y, forwardNorm.z, rightNorm.x, rightNorm.y, rightNorm.z, upNorm.x, upNorm.y, upNorm.z, - position.x, position.y, adjustedZ + position.x, position.y, smoothedZ[pedKey] ) end @@ -128,7 +168,7 @@ RegisterNUICallback('get_config', function(data, cb) action = "config_data", data = { scaling = Config.scaling, - currentScale = syncedScales[tostring(serverId)] or 1.0 -- Default to 1.0, you could store current scale in a variable + currentScale = syncedScales[tostring(serverId)] or 1.0 } }) cb('ok') @@ -145,4 +185,3 @@ RegisterNetEvent('nass_pedscaler:openMenu', function() data = true, }) end) - diff --git a/fxmanifest.lua b/fxmanifest.lua index a5dbc11..c8e7dd9 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,4 +1,4 @@ -version '1.0.0' +version '1.0.1' use_experimental_fxv2_oal 'yes' game 'gta5' diff --git a/web/build/app.js b/web/build/app.js index c7c0dff..44fe321 100644 --- a/web/build/app.js +++ b/web/build/app.js @@ -1,2 +1,2 @@ /*! For license information please see app.js.LICENSE.txt */ -(()=>{"use strict";var e={780:(e,n,t)=>{t.d(n,{Z:()=>u});var r=t(81),l=t.n(r),a=t(645),o=t.n(a)()(l());o.push([e.id,"/* Reset and base styles */\n* {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n}\n\nbody {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'SF Pro Display', system-ui, sans-serif;\n background: transparent;\n color: #ffffff;\n overflow: hidden;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\n@keyframes modalFadeIn {\n to {\n transform: translateY(-50%) scale(1);\n opacity: 1;\n }\n}",""]);const u=o},645:e=>{e.exports=function(e){var n=[];return n.toString=function(){return this.map((function(n){var t="",r=void 0!==n[5];return n[4]&&(t+="@supports (".concat(n[4],") {")),n[2]&&(t+="@media ".concat(n[2]," {")),r&&(t+="@layer".concat(n[5].length>0?" ".concat(n[5]):""," {")),t+=e(n),r&&(t+="}"),n[2]&&(t+="}"),n[4]&&(t+="}"),t})).join("")},n.i=function(e,t,r,l,a){"string"==typeof e&&(e=[[null,e,void 0]]);var o={};if(r)for(var u=0;u0?" ".concat(c[5]):""," {").concat(c[1],"}")),c[5]=a),t&&(c[2]?(c[1]="@media ".concat(c[2]," {").concat(c[1],"}"),c[2]=t):c[2]=t),l&&(c[4]?(c[1]="@supports (".concat(c[4],") {").concat(c[1],"}"),c[4]=l):c[4]="".concat(l)),n.push(c))}},n}},81:e=>{e.exports=function(e){return e[1]}},448:(e,n,t)=>{var r=t(294),l=t(840);function a(e){for(var n="https://reactjs.org/docs/error-decoder.html?invariant="+e,t=1;t