// Declared public member fields and properties will show in the game studio public override void Update() { if (Input.IsKeyDown(Keys.R)) { var raycastStart = Entity.Transform.Parent.WorldMatrix.TranslationVector; var forward = Entity.Transform.Parent.WorldMatrix.Forward; var raycastEnd = raycastStart + forward * MaxHeatUpDistance; var result = this.GetSimulation().Raycast(raycastStart, raycastEnd); if (result.Succeeded && result.Collider != null) { if (result.Collider is RigidbodyComponent rigidBody) { var target = Entity.Scene.Entities.First(e => e.Get <RigidbodyComponent>() == rigidBody && e.Get <ThermalConductionScript>() != null); if (target != null) { DebugText.Print("Temperature target : " + target, new Int2(x: 50, y: 125)); } target?.Get <ThermalConductionScript>()?.HeatUp(CalorPerSec * (float)Game.UpdateTime.Elapsed.TotalSeconds); } } } }
public override void Update() { // First lets check if we have a keyboard. if (Input.HasKeyboard) { // Key down is used for when a key is being held down. DebugText.Print("Hold the 1 key down to rotate the blue teapot", new Int2(340, 500)); if (Input.IsKeyDown(Keys.D1)) { var deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds; BlueTeapot.Transform.Rotation *= Quaternion.RotationY(0.3f * deltaTime); } // Use 'IsKeyPressed' for a single key press event. DebugText.Print("Press F to rotate the yellow teapot (and to pay respects)", new Int2(340, 520)); if (Input.IsKeyPressed(Keys.F)) { YellowTeapot.Transform.Rotation *= Quaternion.RotationY(-0.4f); } // 'IsKeyReleased' is used for when you want to know when a key is released after being either held down or pressed. DebugText.Print("Press and release the Space bar to rotate the green teapot", new Int2(340, 540)); if (Input.IsKeyReleased(Keys.Space)) { GreenTeapot.Transform.Rotation *= Quaternion.RotationY(0.6f); } } }
// Updates every frame public override void Update() { // Using the 'DebugText.Print' command, we can quickly print information to the screen // NOTE: DebugText only works when debugging the game. During release it is automatically disabled DebugText.Print(parentName, new Int2(580, 580)); DebugText.Print(name, new Int2(800, 580)); }
public override void Update() { DebugText.Print("Press C to load/unload child scene", new Int2(20, 60)); if (Input.IsKeyPressed(Keys.C)) { if (loadedChildScene == null) { // loadedChildScene = Content.Load<Scene>(childSceneToLoad); // Or loadedChildScene = Content.Load(childSceneToLoad); loadedChildScene.Offset = new Vector3(0, 0.5f * loaded, 0); loaded++; // Entity.Scene.Children.Add(loadedChildScene); // Or loadedChildScene.Parent = Entity.Scene; } else { // Entity.Scene.Children.Remove(loadedChildScene); // Or loadedChildScene.Parent = null; Content.Unload(loadedChildScene); loadedChildScene = null; } } }
public override void Update() { Cube?.Transform.Rotate(new Vector3(MathUtil.DegreesToRadians(60) * Game.GetDeltaTime(), 0, 0)); DebugText.Print($"Screen {MainCamera.WorldToScreen(Entity.Transform.Position)}", new Int2(20, 20)); DebugText.Print($"ScreenToWorldRaySegment {MainCamera.ScreenToWorldRaySegment(Input.MousePosition)}", new Int2(20, 40)); if (Input.IsMouseButtonPressed(MouseButton.Left)) { _message = ""; var ray = MainCamera.ScreenToWorldRaySegment(Input.MousePosition); var hitResult = this.GetSimulation().Raycast(ray); if (hitResult.Succeeded) { _message = hitResult.Collider.Entity.Name; MainCamera.Entity.Transform.LookAt(hitResult.Collider.Entity.Transform); TargetAcquired.Broadcast(hitResult.Collider.Entity); } else { TargetAcquired.Broadcast(null); } DebugText.Print($"Clicked on {_message}", new Int2(20, 60)); } //DebugText.Print($"Main {SceneSystem.GetMainCamera() != null}", new Int2(20, 40)); }
public override void Update() { int drawX = 40; int drawY = 80; DebugText.Print("Press Q and E to raise/lower weapons", new Int2(drawX, drawY)); var raycastStart = Entity.Transform.Position; var raycastEnd = Entity.Transform.Position + new Vector3(0, 0, maxDistance); drawY += 40; // Send a raycast from the start to the endposition if (simulation.Raycast(raycastStart, raycastEnd, out HitResult hitResult, CollisionFilterGroups.DefaultFilter, CollideWithGroup, CollideWithTriggers)) { // If we hit something, calculate the distance to the hitpoint and scale the laser to that distance HitPoint.Transform.Position = hitResult.Point; var distance = Vector3.Distance(hitResult.Point, raycastStart); laser.Transform.Scale.Z = distance; DebugText.Print("Hit a collider", new Int2(drawX, drawY)); DebugText.Print($"Raycast hit distance: {distance}", new Int2(drawX, drawY + 20)); DebugText.Print($"Raycast hit point: {hitResult.Point}", new Int2(drawX, drawY + 40)); DebugText.Print($"Raycast hit entity: {hitResult.Collider.Entity.Name}", new Int2(drawX, drawY + 60)); }
public override void Start() { Game.Services.AddService <ISceneNavigationService>(this); if (StartScene != null) { var navTo = new SceneHistoryItem { Scene = StartScene, KeepLoaded = KeepStartSceneLoaded, }; if (!Content.TryGetAssetUrl(StartScene, out navTo.AssetName) && KeepStartSceneLoaded) { Log.Warning("Start Scene must be an Asset."); } Navigate(navTo, false); } //TODO: Put this else where Script.AddTask(async() => { while (Game.IsRunning) { var y = (int)Game.GraphicsContext.CommandList.Viewport.Height; y -= 10; DebugText.Print($"Number of running tasks: {Script.Scheduler.MicroThreads.Count}", new Int2(0, y)); await Script.NextFrame(); } }); }
public override async Task Execute() { openCollectiveEvents = new List <OpenCollectiveEvent>(); while (Game.IsRunning) { int drawX = 500, drawY = 600; DebugText.Print($"Press A to get Api data from https://opencollective.com/stride3d", new Int2(drawX, drawY)); if (Input.IsKeyPressed(Stride.Input.Keys.G)) { await RetrieveStrideRepos(); await Script.NextFrame(); } foreach (var openCollectiveEvent in openCollectiveEvents) { drawY += 20; DebugText.Print(openCollectiveEvent.Name, new Int2(drawX, drawY)); } // We have to await the next frame. If we don't do this, our game will be stuck in an infinite loop await Script.NextFrame(); } }
// Update is called once per frame public override void Update() { var deltaV = Entity.Transform.WorldMatrix.TranslationVector - followThis.Transform.WorldMatrix.TranslationVector; var targetPos = Entity.Transform.WorldMatrix.TranslationVector; var dt = (float)Game.UpdateTime.Elapsed.TotalSeconds; deltaV.Y = 0; // Debug.Log("delta v" + deltaV); DebugText.Print("target pos" + targetPos, new Int2(100, 200)); DebugText.Print(deltaV.Length().ToString(), new Int2(100, 300)); if (deltaV.Length() > targetDistance) { deltaV = Vector3.Normalize(deltaV) * targetDistance; deltaV.Y = targetHeight; targetPos = followThis.Transform.WorldMatrix.TranslationVector + deltaV; } else { targetPos.Y = followThis.Transform.WorldMatrix.TranslationVector.Y + targetHeight; } Entity.Transform.WorldMatrix.TranslationVector = Vector3.Lerp(Entity.Transform.WorldMatrix.TranslationVector, targetPos, dt); // TODO: fix lastlookat lastLookat = Vector3.Lerp(lastLookat, followThis.Transform.WorldMatrix.TranslationVector, dt); Entity.LookAt(followThis.Transform.Position); }
public override void Update() { int drawX = 700; int drawY = 80; DebugText.Print("Raycast penetration demo", new Int2(drawX, drawY)); var raycastStart = Entity.Transform.Position; var raycastEnd = Entity.Transform.Position + new Vector3(0, 0, -maxDistance); var distance = Vector3.Distance(raycastStart, raycastEnd); laser.Transform.Scale.Z = distance; var hitResults = new List <HitResult>(); simulation.RaycastPenetrating(raycastStart, raycastEnd, hitResults, CollisionFilterGroups.DefaultFilter, CollideWithGroup, CollideWithTriggers); drawY += 40; if (hitResults.Count > 0) { DebugText.Print($"Raycast has hit {hitResults.Count} object(s)", new Int2(drawX, drawY)); foreach (var hitResult in hitResults) { drawY += 20; DebugText.Print($"- Raycast has hit: {hitResult.Collider.Entity.Name}", new Int2(drawX, drawY)); } } else { DebugText.Print("No collider hit", new Int2(drawX, drawY)); } }
public override void Update() { // We store the local and world position of our entity's tranform in a Vector3 variable Vector3 localPosition = Entity.Transform.Position; Vector3 worldPosition = Entity.Transform.WorldMatrix.TranslationVector; // We display the entity's name and its local and world position on screen DebugText.Print(Entity.Name + " - local position: " + localPosition, new Int2(400, 450)); DebugText.Print(Entity.Name + " - world position: " + worldPosition, new Int2(400, 470)); }
public override void Update() { DebugText.Print($"{Info}: {KeyToPress}", new Int2(20, DrawY)); if (Input.IsKeyPressed(KeyToPress)) { Content.Unload(SceneSystem.SceneInstance.RootScene); SceneSystem.SceneInstance.RootScene = Content.Load(SceneToLoad); } }
private void StopOrResumeAnimations(int drawX, int drawY) { DebugText.Print($"S to pause or resume animations", new Int2(drawX, drawY)); if (Input.IsKeyPressed(Keys.S)) { foreach (var playingAnimation in animation.PlayingAnimations) { playingAnimation.Enabled = !playingAnimation.Enabled; } } }
public override void Update() { DebugText.Print("This is the MasterSword, with a Z of 1", new Int2(500, 320)); DebugText.Print("Clone 0 has not been added to the scene and is therefore not visible", new Int2(600, 250)); DebugText.Print("Clone 1 is placed in the same scene as the entity with the script", new Int2(700, 600)); DebugText.Print("Clone 1 got the same world position as the 'MasterSword'...", new Int2(700, 620)); DebugText.Print("... and was then moved to the right", new Int2(700, 640)); DebugText.Print("Clone 2 and 3 are a child of 'MasterSword'.", new Int2(330, 600)); }
public override void Update() { ProcessInput(); UpdateTransform(); var curPrintPos = new Int2(10, 10); DebugText.Print("Move with WASD(QE) keys, hold right mouse button to control camera.", curPrintPos); curPrintPos.Y += 15; DebugText.Print("Press F1 to show/hide RenderTarget.", curPrintPos); }
public override void Update() { DebugText.Print("Clone 0 has not been added to the scene and is therefore not visible", new Int2(330, 680)); DebugText.Print("This is the MasterSword, with a Z of 1", new Int2(320, 520)); DebugText.Print("Clone 1 is placed in the same scene as the entity with the script", new Int2(700, 500)); DebugText.Print("Clone 1 got the same world position as the 'MasterSword'...", new Int2(700, 520)); DebugText.Print("... and was then moved to the right", new Int2(700, 540)); DebugText.Print("Clone 2 is a child of 'MasterSword'.", new Int2(580, 180)); DebugText.Print("Clone 2 got the same world position + local position of the 'MasterSword'", new Int2(580, 200)); }
public override void Update() { DebugText.Print($"Active Camera: {activeCamera} (TAB to switch)", new Int2(24, 24)); if (Input.IsKeyPressed(Keys.Tab)) { cameras[activeCamera].Enabled = false; var nextCameraIndex = (activeCamera + 1) % cameras.Count; cameras[nextCameraIndex].Enabled = true; activeCamera = nextCameraIndex; } }
public override void Update() { // Do stuff every new frame DebugText.Print("Switch has " + (activated?"":"not") + " been activated and current is " + conduct.Conduct, new Int2(500, 100)); if (conduct.Conduct == Current.ON && !activated) { activated = true; } else if (conduct.Conduct == Current.OFF && activated) { activated = false; } }
public override async Task Execute() { while (Game.IsRunning) { DebugText.Print($"Press G to load Api data and Log it", new Int2(500, 200)); if (Input.IsKeyPressed(Stride.Input.Keys.G)) { await RetrieveStrideRepos(); } await Script.NextFrame(); } }
public override void Update() { // The trigger collider can have 0, 1, or multiple collision going on in a single frame var drawY = 280; foreach (var collision in triggerCollider.Collisions) { DebugText.Print("ColliderA: " + collision.ColliderA.Entity.Name, new Int2(500, drawY += 20)); DebugText.Print("ColliderB: " + collision.ColliderB.Entity.Name, new Int2(500, drawY += 20)); } DebugText.Print(collisionStatus, new Int2(500, 400)); }
private void Accelerate() { speed = rb.LinearVelocity.X * 3.6; if (speed < topSpeed) { rb.ApplyForce(Entity.Transform.WorldMatrix.Forward * engineForce * verticalInput); DebugText.Print("speed " + Math.Round(speed), new Int2(100, 200)); if (speed < 0 && speed > -100) { DebugText.Print(Math.Abs(Math.Round(speed)) + " (R)", new Int2(100, 200)); } } }
private void AdjustAnimationSpeed(int drawX, int drawY) { DebugText.Print($"Q and E for speed {AnimationSpeed:0.0}", new Int2(drawX, drawY)); if (Input.IsKeyPressed(Keys.E)) { AnimationSpeed += 0.1f; latestAnimation.TimeFactor = AnimationSpeed; } if (Input.IsKeyPressed(Keys.Q)) { AnimationSpeed -= 0.1f; latestAnimation.TimeFactor = AnimationSpeed; } }
public override void Update() { var backBuffer = GraphicsDevice.Presenter.BackBuffer; var sphereProjection = Vector3.Project(projectSphere.Transform.WorldMatrix.TranslationVector, 0, 0, backBuffer.Width, backBuffer.Height, 0, 8, camera.ViewProjectionMatrix); var sphereChildProjection = Vector3.Project(projectSphereChild.Transform.WorldMatrix.TranslationVector, 0, 0, backBuffer.Width, backBuffer.Height, 0, 8, camera.ViewProjectionMatrix); // Similar method using Viewports //var viewport = new Viewport(0, 0, backBuffer.Width, backBuffer.Height); //var sphereProjection = viewport.Project(projectSphere.Transform.WorldMatrix.TranslationVector, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); //var sphereChildProjection = viewport.Project(projectSphereChild.Transform.WorldMatrix.TranslationVector, camera.ProjectionMatrix, camera.ViewMatrix, Matrix.Identity); DebugText.Print($"Parent", new Int2(sphereProjection.XY())); DebugText.Print($"Child", new Int2(sphereChildProjection.XY())); }
public override void Update() { // We use a simple timer timer += (float)Game.UpdateTime.Elapsed.TotalSeconds; if (timer > currentTimer) { // If the entities exist, we remove them from the scene if (entitiesExist) { // We remove the cloned entity that is a child of the current entity Entity.RemoveChild(clonedEntity1); // Alternative: clonedEntity1.Transform.Parent = null; // We remove the cloned entity from the scene root Entity.Scene.Entities.Remove(clonedEntity2); // We also need to set the clones to null, otherwise the clones still exist clonedEntity1 = null; clonedEntity2 = null; entitiesExist = false; currentTimer = goneTime; } else // If the entities don't exist, we create new clones { CloneEntityAndAddToScene(); CloneEntityAndAddAsChild(); entitiesExist = true; currentTimer = existTime; } // Reset timer timer = 0; } DebugText.Print("For " + existTime.ToString() + " seconds: ", new Int2(860, 240)); DebugText.Print("- Clone 1 is a child of the script entity", new Int2(860, 260)); DebugText.Print("- Clone 2 is a child of the scene root", new Int2(860, 280)); DebugText.Print("For " + goneTime.ToString() + " seconds, the cloned entities are gone", new Int2(860, 300)); if (entitiesExist) { DebugText.Print("Cloned entity 1 is a child of the Script entity", new Int2(450, 350)); DebugText.Print("Cloned entity 2 is in the scene root", new Int2(450, 600)); } else { DebugText.Print("Cloned entity 1 and 2 have been removed", new Int2(450, 600)); } }
public override void Update() { // We retrieve a float value from the virtual button. When the value is higher than 0, we know that we have at least one of the keys or mouse pressed var movingForward = Input.GetVirtualButton(0, "Forward"); if (movingForward > 0) { var deltaTime = (float)Game.UpdateTime.Elapsed.TotalSeconds; BlueTeapot.Transform.Rotation *= Quaternion.RotationY(0.6f * deltaTime); } DebugText.Print("Hold down W, the Up arrow or the left mouse button, to rotate the blue teapot", new Int2(600, 200)); DebugText.Print("Virtual button 'Forward': " + movingForward, new Int2(600, 220)); }
public override async Task Execute() { musicInstance = BackgroundMusic.CreateInstance(); // Wait till the music is done loading await musicInstance.ReadyToPlay(); while (Game.IsRunning) { // Play or pause DebugText.Print($"Space to play/pause. Currently: {musicInstance.PlayState}", new Int2(800, 40)); if (Input.IsKeyPressed(Keys.Space)) { if (musicInstance.PlayState == PlayState.Playing) { musicInstance.Pause(); } else { musicInstance.Play(); } } // Volume DebugText.Print($"Up/Down to change volume: {musicInstance.Volume:0.0}", new Int2(800, 60)); if (Input.IsKeyPressed(Keys.Up)) { musicInstance.Volume = Math.Clamp(musicInstance.Volume + 0.1f, 0, 2); } if (Input.IsKeyPressed(Keys.Down)) { musicInstance.Volume = Math.Clamp(musicInstance.Volume - 0.1f, 0, 2); } // Panning DebugText.Print($"Left/Right to change panning: {musicInstance.Pan:0.0}", new Int2(800, 80)); if (Input.IsKeyPressed(Keys.Left)) { musicInstance.Pan = Math.Clamp(musicInstance.Pan - 0.1f, -1, 1); } if (Input.IsKeyPressed(Keys.Right)) { musicInstance.Pan = Math.Clamp(musicInstance.Pan + 0.1f, -1, 1); } // Wait for next frame await Script.NextFrame(); } }
public override void Update() { DebugText.Print("Press Space to teleport ball back in the air", new Int2(500, 180)); if (Input.IsKeyPressed(Keys.Space)) { Ball.Transform.Position = Entity.Transform.WorldMatrix.TranslationVector; Ball.Transform.UpdateWorldMatrix(); // We have to update the physics transform since we manually positioned the ball's position var physicsComponent = Ball.Get <RigidbodyComponent>(); physicsComponent.LinearVelocity = new Vector3(); physicsComponent.UpdatePhysicsTransformation(); } }
public override void Update() { float dt = (float)Game.UpdateTime.Elapsed.TotalSeconds; const float FORCE_PER_SECOND = 10; if (Input.IsKeyDown(Keys.Right)) { vehicleBody.ApplyImpulse(Entity.Transform.WorldMatrix.Left * FORCE_PER_SECOND * dt); } else if (Input.IsKeyDown(Keys.Left)) { vehicleBody.ApplyImpulse(Entity.Transform.WorldMatrix.Right * FORCE_PER_SECOND * dt); } DebugText.Print("Left/Right Arrow Key to move the vehicle", new Int2(32, 32)); }
public override void Update() { var x = 400; DebugText.Print("Integer: " + SomeInteger, new Int2(x, 200)); DebugText.Print("Float: " + SomeFloat, new Int2(x, 220)); DebugText.Print("Boolean: " + SomeBoolean, new Int2(x, 240)); DebugText.Print("String: " + SomeString, new Int2(x, 260)); DebugText.Print("Vector2: " + SomeVector2, new Int2(x, 280)); DebugText.Print("Vector3: " + SomeVector3, new Int2(x, 300)); DebugText.Print("Vector4: " + SomeVector4, new Int2(x, 320)); DebugText.Print("Color: " + SomeColor, new Int2(x, 340)); DebugText.Print("String list count: " + StringList.Count, new Int2(x, 360)); DebugText.Print("Entity list count: " + EntityList.Count, new Int2(x, 380)); DebugText.Print("Camera list count: " + CameraList.Count, new Int2(x, 400)); }
public override void Update() { if (Conduct == Current.ON) { DebugText.Print(Entity.Name + " has " + collisionNumber + "collisions", new Int2(900, 25 * (int)Entity.Name.Length)); } int temp = CountCollision(); if (collisionNumber != temp) { currentChange.Broadcast(); collisionNumber = temp; } }