private void RemoveCharacterController(MoverComponent mover) { if (ControllerMap.TryGetValue(mover, out var ctrl)) { //? } }
public override void InitPhysicsComponent() { Info = GetComponent <PhysicsInfo>(); _mover = GetComponent <MoverComponent>(); Radius = transform.localScale.x * 0.5f; }
public override void init() { GameObject[] players = GameObject.FindGameObjectsWithTag("LocateTrack"); foreach (GameObject p in players) { MoverComponent cmpareTo = p.GetComponent <MoverComponent> (); if (cmpareTo && (cmpareTo != localPlayer)) { target = cmpareTo; } } if (!target) { target = localPlayer; } this.controlledView.CameraComposerTarget = target.transform; }
public Player(bool useDynamicController) { var xform = new TransformComponent(this, Quaternion.Identity); xform.Position = new Vector3(0, 0, 8); xform.UpdateDerivedData(); var light = new PointLightEmitterComponent(this); light.Light = new Foundation.PointLight() { Position = Vector3.Zero, Color = new Vector3(0.3f, 1f, 0.3f), Radius = 20f }; var moverConfig = new MoverComponent.MovementConfig() { Mode = useDynamicController ? MoverComponent.MovementMode.DynamicCharacterControl : MoverComponent.MovementMode.KinematicCharacterControl, Speed = 0.1f, }; var dynamic = new DynamicMovementController(); var mover = new MoverComponent(this, xform, moverConfig, dynamic); dynamic.Mover = mover; var camera = new CameraComponent(this); camera.PositionOffset = moverConfig.EyeOffset; this.EyeOffset = moverConfig.EyeOffset; var listener = new SoundListenerComponent(this, xform); this.SetComponents(xform, listener, mover, camera); }
////////////////////////////////////////////////////////////////////////////////////////// #region Constructors ////////////////////////////////////////////////////////////////////////////////////////// public MoveAction(MoverComponent moverComponent, MoverComponent.ActionTypeFlag actionTypeFlag) { Debug.Assert(moverComponent != null, "Error: MoverComponent provided was null."); m_moverComponent = moverComponent; m_actionTypeFlag = actionTypeFlag; }
// TODO: Currently, this system is responsible for creating and setting PhysicsImplementation properties // -issue: PhysicsImplementations can't be passed/delegated before this system is initialized, as the props are unset // -motive: DynamicMovementController wants to be able to setup callbacks before any physics events happen public void AddCharacterController(MoverComponent component) { var config = component.Config; var radius = 0.175f; // TODO: reduce duplicated code if (component.Mode == MoverComponent.MovementMode.Freecam) { var posPose = Matrix4x4.CreateTranslation(component.Transform.TransformationMatrix.Translation); var rot = Matrix4x4.CreateRotationY(MathF.PI / -2f); var body = this.physxPhysics.CreateRigidDynamic(rot * posPose); body.MassSpaceInertiaTensor = new Vector3(0, 0, 0); body.Mass = 175f; body.UserData = component; body.RigidBodyFlags = RigidBodyFlag.Kinematic; var capsuleDesc = new CapsuleGeometry(radius, config.Height / 2f - radius); var shape = RigidActorExt.CreateExclusiveShape(body, capsuleDesc, characterControlMat); // TODO: centralize filter data construction shape.SimulationFilterData = new FilterData((uint)(OpenH2FilterData.NoClip | OpenH2FilterData.PlayerCharacter), 0, 0, 0); shape.ContactOffset = 0.001f; shape.RestOffset = 0.0009f; var bodyProxy = new RigidBodyProxy(body); component.PhysicsImplementation = bodyProxy; this.physxScene.AddActor(body); } if (component.Mode == MoverComponent.MovementMode.KinematicCharacterControl) { var desc = new CapsuleControllerDesc() { Height = config.Height - .02f - (2 * radius), Position = component.Transform.Position, Radius = radius, MaxJumpHeight = 1f, UpDirection = EngineGlobals.Up, SlopeLimit = MathF.Cos(0.872665f), // cos(50 degrees) StepOffset = 0.1f, Material = defaultMat, ContactOffset = 0.0001f, ReportCallback = new CustomHitReport() }; var controller = this.controllerManager.CreateController <CapsuleController>(desc); controller.Actor.UserData = component; component.PhysicsImplementation = new KinematicCharacterControllerProxy(controller); this.ControllerMap.Add(component, controller); } else if (component.Mode == MoverComponent.MovementMode.DynamicCharacterControl) { var posPose = Matrix4x4.CreateTranslation(component.Transform.TransformationMatrix.Translation); var rot = Matrix4x4.CreateRotationY(MathF.PI / -2f); var body = this.physxPhysics.CreateRigidDynamic(rot * posPose); body.MassSpaceInertiaTensor = new Vector3(0, 0, 0); body.Mass = 175f; body.UserData = component; var capsuleDesc = new CapsuleGeometry(radius, config.Height / 2f - radius); var shape = RigidActorExt.CreateExclusiveShape(body, capsuleDesc, characterControlMat); // TODO: centralize filter data construction shape.SimulationFilterData = new FilterData((uint)OpenH2FilterData.PlayerCharacter, 0, 0, 0); shape.ContactOffset = 0.001f; shape.RestOffset = 0.0009f; var bodyProxy = new RigidBodyProxy(body); component.PhysicsImplementation = bodyProxy; this.physxScene.AddActor(body); if (component.State is DynamicMovementController dynamicMover) { var contactInfo = ContactCallbackData.Normal; this.contactProvider.RegisterContactCallback(body, contactInfo, dynamicMover.ContactFound); } } }
////////////////////////////////////////////////////////////////////////////////////////// #region Attributes ////////////////////////////////////////////////////////////////////////////////////////// #endregion ////////////////////////////////////////////////////////////////////////////////////////// #region Constructors ////////////////////////////////////////////////////////////////////////////////////////// public JumpMoveAction(MoverComponent moverComponent) : base(moverComponent, MoverComponent.ActionTypeFlag.Jump) { }
public override void OnInspectorGUI() { serializedObject.Update(); MoverComponent moverComponent = target as MoverComponent; EditorGUI.BeginChangeCheck(); bool alwaysUpdate = EditorGUILayout.Toggle("Always Update", moverComponent.getAlwaysUpdate()); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Always Update"); EditorUtility.SetDirty(moverComponent); moverComponent.setAlwaysUpdate(alwaysUpdate); } EditorGUILayout.LabelField("Affected Transform"); EditorGUI.BeginChangeCheck(); Transform transformComponent = (Transform)EditorGUILayout.ObjectField(moverComponent.getTransform(), typeof(Transform), true); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Affected Transform"); EditorUtility.SetDirty(moverComponent); moverComponent.setTransform(transformComponent); } EditorGUI.BeginChangeCheck(); MoverComponent.ActionTypeFlag allActions = (MoverComponent.ActionTypeFlag)EditorGUILayout.EnumMaskField("Mover Actions", moverComponent.getActionTypeFlags()); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Mover Actions"); EditorUtility.SetDirty(moverComponent); moverComponent.setActionTypeFlags(allActions); } Dictionary <MoverComponent.ActionTypeFlag, Mover> actionMoverBehaviors = moverComponent.getActionMovers(); int actionTypeFlagCount = System.Enum.GetValues(typeof(MoverComponent.ActionTypeFlag)).Length; for (int i = 0; i < actionTypeFlagCount; ++i) { MoverComponent.ActionTypeFlag mask = (MoverComponent.ActionTypeFlag)(1 << i); MoverComponent.ActionTypeFlag maskedActionTypeFlag = mask & allActions; if (maskedActionTypeFlag != 0) { bool displayFoldout; if (!m_actionTypeFlagFoldoutDisplay.TryGetValue(maskedActionTypeFlag, out displayFoldout)) { m_actionTypeFlagFoldoutDisplay.Add(maskedActionTypeFlag, true); displayFoldout = m_defaultFoldout; } m_actionTypeFlagFoldoutDisplay[maskedActionTypeFlag] = EditorGUILayout.Foldout(displayFoldout, maskedActionTypeFlag.ToString()); if (displayFoldout) { moverComponent.createMoverAction(maskedActionTypeFlag); Mover mover = actionMoverBehaviors[maskedActionTypeFlag]; EditorGUILayout.LabelField("Mover Behaviour"); EditorGUI.BeginChangeCheck(); MoverBehavior moverBehavior = (MoverBehavior)EditorGUILayout.ObjectField(mover.getMoverBehavior(), typeof(MoverBehavior), true); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Mover Behaviour"); EditorUtility.SetDirty(moverComponent); mover.setMoverBehavior(moverBehavior); } if (moverBehavior != null) { createMoverBehaviorUI(moverBehavior); EditorGUI.BeginChangeCheck(); InterpolationHelper.InterpolationType interpolationType = (InterpolationHelper.InterpolationType)EditorGUILayout.EnumPopup("Interpolation Type", mover.getInterpolationType()); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Interpolation Type"); EditorUtility.SetDirty(moverComponent); mover.setInterpolationType(interpolationType); } if (interpolationType != InterpolationHelper.InterpolationType.None && interpolationType != InterpolationHelper.InterpolationType.Undefined) { if (interpolationType != InterpolationHelper.InterpolationType.Linear) { EditorGUI.BeginChangeCheck(); InterpolationHelper.EasingType easingType = (InterpolationHelper.EasingType)EditorGUILayout.EnumPopup("Easing Type", mover.getEasingType()); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Easing Type"); EditorUtility.SetDirty(moverComponent); mover.setEasingType(easingType); } } EditorGUI.BeginChangeCheck(); float duration = EditorGUILayout.FloatField("Duration (seconds)", mover.getDuration()); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Duration"); EditorUtility.SetDirty(moverComponent); mover.setDuration(duration); } EditorGUI.BeginChangeCheck(); float updateRate = EditorGUILayout.FloatField("Update Rate (seconds)", mover.getUpdateRate()); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(moverComponent, "Update Rate"); EditorUtility.SetDirty(moverComponent); mover.setUpdateRate(updateRate); } } } } } else { moverComponent.removeMoverAction(mask); } } serializedObject.ApplyModifiedProperties(); }