First things on the physics object

This commit is contained in:
2026-02-18 12:40:08 +00:00
parent cb4780d0e2
commit e48b4e1b81
2 changed files with 192 additions and 4 deletions

View File

@@ -176,6 +176,119 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: d943606e96a65aeceaa19bb4a56c515b, type: 3} m_Script: {fileID: 11500000, guid: d943606e96a65aeceaa19bb4a56c515b, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: '::' m_EditorClassIdentifier: '::'
--- !u!1 &109735446
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 109735450}
- component: {fileID: 109735449}
- component: {fileID: 109735448}
- component: {fileID: 109735447}
m_Layer: 0
m_Name: Plane
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!64 &109735447
MeshCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 109735446}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 5
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &109735448
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 109735446}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RayTracingAccelStructBuildFlagsOverride: 0
m_RayTracingAccelStructBuildFlags: 1
m_SmallMeshCulling: 1
m_ForceMeshLod: -1
m_MeshLodSelectionBias: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_GlobalIlluminationMeshLod: 0
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_MaskInteraction: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!33 &109735449
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 109735446}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &109735450
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 109735446}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.07281, y: -1.142, z: 0.5}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &116930897 --- !u!1 &116930897
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1458,6 +1571,7 @@ GameObject:
- component: {fileID: 1172921197} - component: {fileID: 1172921197}
- component: {fileID: 1172921199} - component: {fileID: 1172921199}
- component: {fileID: 1172921198} - component: {fileID: 1172921198}
- component: {fileID: 1172921200}
m_Layer: 0 m_Layer: 0
m_Name: PhysicsBody m_Name: PhysicsBody
m_TagString: Untagged m_TagString: Untagged
@@ -1493,6 +1607,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: '::' m_EditorClassIdentifier: '::'
mainEngine: {fileID: 1437557825} mainEngine: {fileID: 1437557825}
rb: {fileID: 1172921199}
altimeter: {fileID: 894314916}
--- !u!54 &1172921199 --- !u!54 &1172921199
Rigidbody: Rigidbody:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1515,11 +1631,32 @@ Rigidbody:
m_Bits: 0 m_Bits: 0
m_ImplicitCom: 1 m_ImplicitCom: 1
m_ImplicitTensor: 1 m_ImplicitTensor: 1
m_UseGravity: 1 m_UseGravity: 0
m_IsKinematic: 0 m_IsKinematic: 0
m_Interpolate: 0 m_Interpolate: 0
m_Constraints: 0 m_Constraints: 0
m_CollisionDetection: 0 m_CollisionDetection: 2
--- !u!65 &1172921200
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1172921196}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
m_Bits: 0
m_ExcludeLayers:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1240885343 --- !u!1 &1240885343
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1863,3 +2000,4 @@ SceneRoots:
- {fileID: 503400737} - {fileID: 503400737}
- {fileID: 989507026} - {fileID: 989507026}
- {fileID: 740085062} - {fileID: 740085062}
- {fileID: 109735450}

View File

@@ -1,20 +1,70 @@
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
public class RocketPhysics : MonoBehaviour public class RocketPhysics : MonoBehaviour
{ {
[Header("References")] [Header("References")]
public MainEngine mainEngine; public MainEngine mainEngine;
public Rigidbody rb;
public Altimeter altimeter;
[Header("Data")]
public DoublePrecisionVector3 position;
public DoublePrecisionVector3 velocity;
public DoublePrecisionVector3 rotation;
// Start is called once before the first execution of Update after the MonoBehaviour is created // Start is called once before the first execution of Update after the MonoBehaviour is created
void Start() void Start()
{ {
position = new DoublePrecisionVector3(rb.position.x, rb.position.y, rb.position.z);
velocity = new DoublePrecisionVector3(rb.linearVelocity.x, rb.linearVelocity.y, rb.linearVelocity.z);
rotation = new DoublePrecisionVector3(rb.rotation.eulerAngles.x, rb.rotation.eulerAngles.y, rb.rotation.eulerAngles.z);
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
double gravityAcceleration = altimeter.gh;
double thrustAcceleration = mainEngine.thrust / rb.mass;
Vector3 thrustDirection = rb.rotation * Vector3.up;
DoublePrecisionVector3 gravityAccelerationVector = new DoublePrecisionVector3(0, -gravityAcceleration, 0);
DoublePrecisionVector3 thrustAccelerationVector = new DoublePrecisionVector3(
thrustDirection.x * thrustAcceleration,
thrustDirection.y * thrustAcceleration,
thrustDirection.z * thrustAcceleration
);
DoublePrecisionVector3 totalAcceleration = gravityAccelerationVector + thrustAccelerationVector;
velocity = velocity + totalAcceleration * Time.deltaTime;
position = position + velocity * Time.deltaTime;
rb.position = new Vector3((float)position.x, (float)position.y, (float)position.z);
rb.linearVelocity = new Vector3((float)velocity.x, (float)velocity.y, (float)velocity.z);
rb.rotation = Quaternion.Euler((float)rotation.x, (float)rotation.y, (float)rotation.z);
} }
} }
public class DoublePrecisionVector3
{
public double x;
public double y;
public double z;
public DoublePrecisionVector3(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
public static DoublePrecisionVector3 operator +(DoublePrecisionVector3 a, DoublePrecisionVector3 b)
{
return new DoublePrecisionVector3(a.x + b.x, a.y + b.y, a.z + b.z);
}
public static DoublePrecisionVector3 operator *(DoublePrecisionVector3 a, double d)
{
return new DoublePrecisionVector3(a.x * d, a.y * d, a.z * d);
}
}