new car camera

This commit is contained in:
Valera 2025-06-14 18:21:37 +07:00
parent 265af16061
commit 969c8e3bd0
4 changed files with 290 additions and 24 deletions

View File

@ -4978,9 +4978,10 @@
"__type": "VeloX.VeloXWheel",
"__guid": "64e23ffa-c2d8-4d1b-97e2-2e6ec074e350",
"__enabled": true,
"Ackermann": 0,
"AutoPhysics": true,
"BrakePowerMax": 3000,
"CamberAngle": -5,
"CamberAngle": 0,
"CasterAngle": 0,
"IsFront": true,
"Mass": 30,
@ -4997,8 +4998,8 @@
"SpringStrength": 2800,
"SteerMultiplier": 1,
"SuspensionLength": 5,
"ToeAngle": -0.5,
"WheelFriction": "frictions/high-performance road tire.whfric",
"TirePreset": "frictions/default.tire",
"ToeAngle": 0,
"Width": 9
}
],
@ -5084,9 +5085,10 @@
"__type": "VeloX.VeloXWheel",
"__guid": "1863c712-5c7c-427b-b734-87b732d65502",
"__enabled": true,
"Ackermann": 0,
"AutoPhysics": true,
"BrakePowerMax": 3000,
"CamberAngle": 5,
"CamberAngle": 0,
"CasterAngle": 0,
"IsFront": true,
"Mass": 30,
@ -5103,8 +5105,8 @@
"SpringStrength": 2800,
"SteerMultiplier": 1,
"SuspensionLength": 5,
"ToeAngle": 0.5,
"WheelFriction": "frictions/high-performance road tire.whfric",
"TirePreset": "frictions/default.tire",
"ToeAngle": 0,
"Width": 9
}
],
@ -5190,9 +5192,10 @@
"__type": "VeloX.VeloXWheel",
"__guid": "32fbede7-4c34-4f7d-8ec3-594774e693dc",
"__enabled": true,
"Ackermann": 0,
"AutoPhysics": true,
"BrakePowerMax": 3000,
"CamberAngle": -3,
"CamberAngle": 0,
"CasterAngle": 0,
"IsFront": false,
"Mass": 30,
@ -5209,8 +5212,8 @@
"SpringStrength": 2800,
"SteerMultiplier": 0,
"SuspensionLength": 5,
"ToeAngle": -0.5,
"WheelFriction": "frictions/high-performance road tire.whfric",
"TirePreset": "frictions/default.tire",
"ToeAngle": 0,
"Width": 9
}
],
@ -5296,9 +5299,10 @@
"__type": "VeloX.VeloXWheel",
"__guid": "52e26121-2451-4373-b101-a2d7a4e51a09",
"__enabled": true,
"Ackermann": 0,
"AutoPhysics": true,
"BrakePowerMax": 3000,
"CamberAngle": 3,
"CamberAngle": 0,
"CasterAngle": 0,
"IsFront": false,
"Mass": 30,
@ -5315,8 +5319,8 @@
"SpringStrength": 2800,
"SteerMultiplier": 0,
"SuspensionLength": 5,
"ToeAngle": 0.5,
"WheelFriction": "frictions/high-performance road tire.whfric",
"TirePreset": "frictions/default.tire",
"ToeAngle": 0,
"Width": 9
}
],
@ -5418,7 +5422,6 @@
"__type": "VeloX.Powertrain.Engine",
"__guid": "0bc0d7ab-0688-4447-bb86-271c960a4cd8",
"__enabled": true,
"FrictionCoeff": 0.01,
"IdleRPM": 900,
"Inertia": 0.151,
"Input": null,
@ -5438,7 +5441,6 @@
"component_type": "Clutch"
},
"RPMPercent": 0,
"StartFriction": -10,
"Stream": "sounds/streams/v8_c63/v8_c63.engstr",
"TorqueMap": {
"rangey": "0,200",
@ -5608,7 +5610,6 @@
"__guid": "57ceb391-79ea-4d2d-a27f-cdd3c18e5789",
"__enabled": true,
"BiasAB": 0.5,
"CoastRamp": 1,
"FinalDrive": 3.392,
"Inertia": 0.01,
"Input": {
@ -5635,10 +5636,6 @@
"go": "df6aec6f-b56f-4696-bd56-ffc02fc99bd3",
"component_type": "PowerWheel"
},
"PowerRamp": 1,
"SlipTorque": 0,
"SteerLock": 45,
"Stiffness": 0.1,
"Vehicle": {
"_type": "component",
"component_id": "03e04bce-db7b-4547-9cfd-0364849bdb33",

View File

@ -626,6 +626,262 @@
}
],
"Children": []
},
{
"__guid": "645d1465-69e8-4e2e-a3af-3f68da8164d1",
"__version": 1,
"Flags": 0,
"Name": "Cube",
"Position": "500,0,0",
"Rotation": "0.04361939,0,0,0.9990482",
"Scale": "10,50,1",
"Tags": "",
"Enabled": true,
"NetworkMode": 2,
"NetworkInterpolation": true,
"NetworkOrphaned": 0,
"OwnerTransfer": 1,
"Components": [
{
"__type": "Sandbox.ModelRenderer",
"__guid": "7db79076-4eec-4f27-8842-bc65c970d957",
"__enabled": true,
"BodyGroups": 18446744073709551615,
"CreateAttachments": false,
"MaterialGroup": null,
"MaterialOverride": "materials/emo.vmat",
"Model": "models/dev/box.vmdl",
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"RenderOptions": {
"GameLayer": true,
"OverlayLayer": false,
"BloomLayer": false,
"AfterUILayer": false
},
"RenderType": "On",
"Tint": "1,1,1,1"
},
{
"__type": "Sandbox.BoxCollider",
"__guid": "3910b51a-8e0e-488c-963e-01f79ebbba32",
"__enabled": true,
"Center": "0,0,0",
"Friction": null,
"IsTrigger": false,
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"OnObjectTriggerEnter": null,
"OnObjectTriggerExit": null,
"OnTriggerEnter": null,
"OnTriggerExit": null,
"Scale": "50,50,50",
"Static": false,
"Surface": null,
"SurfaceVelocity": "0,0,0"
}
],
"Children": []
},
{
"__guid": "40386ba9-c7fb-41ef-a1f3-f5f0066ee482",
"__version": 1,
"Flags": 0,
"Name": "Cube (3)",
"Position": "1000,0,0",
"Rotation": "0.08715574,0,0,0.9961947",
"Scale": "10,50,1",
"Tags": "",
"Enabled": true,
"NetworkMode": 2,
"NetworkInterpolation": true,
"NetworkOrphaned": 0,
"OwnerTransfer": 1,
"Components": [
{
"__type": "Sandbox.ModelRenderer",
"__guid": "af2039a1-88e5-4961-9f27-45cc2d0e9906",
"__enabled": true,
"BodyGroups": 18446744073709551615,
"CreateAttachments": false,
"MaterialGroup": null,
"MaterialOverride": "materials/emo.vmat",
"Model": "models/dev/box.vmdl",
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"RenderOptions": {
"GameLayer": true,
"OverlayLayer": false,
"BloomLayer": false,
"AfterUILayer": false
},
"RenderType": "On",
"Tint": "1,1,1,1"
},
{
"__type": "Sandbox.BoxCollider",
"__guid": "62f5ff5f-e013-476c-9b3c-d9be6dc03005",
"__enabled": true,
"Center": "0,0,0",
"Friction": null,
"IsTrigger": false,
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"OnObjectTriggerEnter": null,
"OnObjectTriggerExit": null,
"OnTriggerEnter": null,
"OnTriggerExit": null,
"Scale": "50,50,50",
"Static": false,
"Surface": null,
"SurfaceVelocity": "0,0,0"
}
],
"Children": []
},
{
"__guid": "e907e11d-cc14-475d-8b84-07553517150f",
"__version": 1,
"Flags": 0,
"Name": "Cube (4)",
"Position": "1500,0,0",
"Rotation": "0.1305262,0,0,0.9914449",
"Scale": "10,50,1",
"Tags": "",
"Enabled": true,
"NetworkMode": 2,
"NetworkInterpolation": true,
"NetworkOrphaned": 0,
"OwnerTransfer": 1,
"Components": [
{
"__type": "Sandbox.ModelRenderer",
"__guid": "6c2d01d0-7492-4d4c-9021-0570aea9fcf1",
"__enabled": true,
"BodyGroups": 18446744073709551615,
"CreateAttachments": false,
"MaterialGroup": null,
"MaterialOverride": "materials/emo.vmat",
"Model": "models/dev/box.vmdl",
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"RenderOptions": {
"GameLayer": true,
"OverlayLayer": false,
"BloomLayer": false,
"AfterUILayer": false
},
"RenderType": "On",
"Tint": "1,1,1,1"
},
{
"__type": "Sandbox.BoxCollider",
"__guid": "84748465-2e79-4528-b3a0-418f677e36df",
"__enabled": true,
"Center": "0,0,0",
"Friction": null,
"IsTrigger": false,
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"OnObjectTriggerEnter": null,
"OnObjectTriggerExit": null,
"OnTriggerEnter": null,
"OnTriggerExit": null,
"Scale": "50,50,50",
"Static": false,
"Surface": null,
"SurfaceVelocity": "0,0,0"
}
],
"Children": []
},
{
"__guid": "c106b32c-a0e3-4117-b7f9-638c18a96533",
"__version": 1,
"Flags": 0,
"Name": "Cube (5)",
"Position": "2000,0,0",
"Rotation": "0.1736482,0,0,0.9848077",
"Scale": "10,50,1",
"Tags": "",
"Enabled": true,
"NetworkMode": 2,
"NetworkInterpolation": true,
"NetworkOrphaned": 0,
"OwnerTransfer": 1,
"Components": [
{
"__type": "Sandbox.ModelRenderer",
"__guid": "af00dbab-e2fa-4442-aeb0-65c534a87bec",
"__enabled": true,
"BodyGroups": 18446744073709551615,
"CreateAttachments": false,
"MaterialGroup": null,
"MaterialOverride": "materials/emo.vmat",
"Model": "models/dev/box.vmdl",
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"RenderOptions": {
"GameLayer": true,
"OverlayLayer": false,
"BloomLayer": false,
"AfterUILayer": false
},
"RenderType": "On",
"Tint": "1,1,1,1"
},
{
"__type": "Sandbox.BoxCollider",
"__guid": "4f50f469-5bdb-490a-a2fd-e5953788f87d",
"__enabled": true,
"Center": "0,0,0",
"Friction": null,
"IsTrigger": false,
"OnComponentDestroy": null,
"OnComponentDisabled": null,
"OnComponentEnabled": null,
"OnComponentFixedUpdate": null,
"OnComponentStart": null,
"OnComponentUpdate": null,
"OnObjectTriggerEnter": null,
"OnObjectTriggerExit": null,
"OnTriggerEnter": null,
"OnTriggerExit": null,
"Scale": "50,50,50",
"Static": false,
"Surface": null,
"SurfaceVelocity": "0,0,0"
}
],
"Children": []
}
],
"SceneProperties": {

@ -1 +1 @@
Subproject commit 964b46e1c5397a574371edeb06b45b7067b72efa
Subproject commit 629ae6715c9fbddf6fddb5c28c578b1ccdfe36ef

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
@ -19,7 +20,9 @@ namespace Sandbox
[Property] VeloXCar Car { get; set; }
[Property] public Vector3 CameraOffset { get; set; }
private Angles EyeAngles { get; set; }
public float blendSpeed = 10f;
private Angles EyeAngles = new( 0, 180, 0 );
private Rotation targetRotation;
protected override void OnUpdate()
{
@ -34,7 +37,7 @@ namespace Sandbox
Angles input = Input.AnalogLook;
Angles eyeAngles = EyeAngles;
eyeAngles += input;
eyeAngles += input.WithPitch( -input.pitch );
eyeAngles.roll = 0f;
eyeAngles.pitch = eyeAngles.pitch.Clamp( 0f - 89, 89 );
@ -46,8 +49,18 @@ namespace Sandbox
{
var cam = Scene.Camera;
cam.WorldRotation = EyeAngles;
cam.WorldPosition = WorldPosition + Vector3.Up * CameraOffset.z + cam.WorldRotation.Backward * CameraOffset.x;
var zoffset = Vector3.Up * CameraOffset.z;
Vector3 targetPos = WorldPosition + zoffset + WorldRotation * EyeAngles * CameraOffset;
float blendFactor = blendSpeed * Time.Delta;
blendFactor = MathF.Min( blendFactor, 1f );
cam.WorldPosition = Vector3.Lerp( cam.WorldPosition, targetPos, blendFactor );
Vector3 lookDirection = WorldPosition + zoffset - cam.WorldPosition;
if ( lookDirection != Vector3.Zero )
targetRotation = Rotation.LookAt( lookDirection, Vector3.Up );
cam.WorldRotation = targetRotation;
}
}
}