public override void _PhysicsProcess(float delta) { Vector3 targetPosition = (_targetNode as Spatial).GlobalTransform.origin; Vector3 cameraPosition = GlobalTransform.origin; Vector3 deltaPosition = cameraPosition - targetPosition; if (deltaPosition.Length() < _minDistance) { deltaPosition = deltaPosition.Normalized() * _minDistance; } else if (deltaPosition.Length() > _maxDistance) { deltaPosition = deltaPosition.Normalized() * _maxDistance; } if (deltaPosition.y > MaxHeight) { deltaPosition.y = MaxHeight; } if (deltaPosition.y < MinHeight) { deltaPosition.y = MinHeight; } cameraPosition = targetPosition + deltaPosition; LookAtFromPosition(cameraPosition, targetPosition, Vector3.Up); Transform newTransform = Transform; newTransform.basis = new Basis(newTransform.basis[0], Mathf.Deg2Rad(_angleVadjust)) * newTransform.basis; Transform = newTransform; }
private void LaunchChargedAttack() { if (_chargedBullet == null) { return; } Vector2 launchPosition = _dualArmAttackPosition.GetGlobalPosition(); float launchAngle = -Mathf.Rad2Deg(Mathf.Atan2( launchPosition.x - PlayerVariables.LastPlayerPosition.x, launchPosition.y - PlayerVariables.LastPlayerPosition.y )) - 90; float xVelocity = Mathf.Cos(Mathf.Deg2Rad(launchAngle)); float yVelocity = Mathf.Sin(Mathf.Deg2Rad(launchAngle)); Vector2 launchVelocity = new Vector2(xVelocity, yVelocity); _dualArmAttackPosition.RemoveChild(_chargedBullet); _bulletHolder.AddChild(_chargedBullet); _chargedBullet.SetMode(RigidBody2D.ModeEnum.Rigid); _chargedBullet.LaunchBullet(launchVelocity.Normalized()); _chargedBullet.SetAsDynamicBullet(); _chargedBullet.SetGlobalPosition(launchPosition); _chargedBullet.SetGlobalScale(Vector2.One * _attackVariable_1); _chargedEffectDestroy.DestroyNode(); _attackVariable_1 = 0; _chargedEffectDestroy = null; _chargedBullet = null; }
public override void _Input(InputEvent inputEvent) { if (inputEvent is InputEventMouseButton button) { if ((ButtonList)button.ButtonIndex == ButtonList.Right) { if (drag != true) { drag = true; } else { drag = false; } //MouseCameraControl(inputEvent); } } if (inputEvent is InputEventMouseMotion motion && drag) { //GlobalRotate(new Vector3(1,0,0), Mathf.Deg2Rad(motion.Relative.y*RotationSpeed)); RotateX(Mathf.Deg2Rad(motion.Relative.y * RotationSpeed)); var rot = RotationDegrees; rot.x = Mathf.Clamp(rot.x, -80, 80); RotationDegrees = rot; } }
private void Movement(float delta) { Vector3 direction = new Vector3(); if (Input.IsActionPressed("MoveForward")) { mesh.RotateX(Mathf.Deg2Rad(velocity.z * rotationSpeed)); direction -= Transform.basis.z; } if (Input.IsActionPressed("MoveBackward")) { mesh.RotateX(Mathf.Deg2Rad(velocity.z * rotationSpeed)); direction += Transform.basis.z; } if (Input.IsActionPressed("MoveLeft")) { mesh.RotateZ(Mathf.Deg2Rad(-velocity.x * rotationSpeed)); direction -= Transform.basis.x; } if (Input.IsActionPressed("MoveRight")) { direction += Transform.basis.x; mesh.RotateZ(Mathf.Deg2Rad(-velocity.x * rotationSpeed)); } direction = direction.Normalized(); velocity = velocity.LinearInterpolate(direction * speed, acceleration * delta); MoveAndSlide(velocity); }
private static System.Nullable <Vector3> WallBranch(Structure Base) { switch (Base.Type) { case (Items.TYPE.PLATFORM): { float Rotation = Mathf.Deg2Rad(SnapToGrid(Game.PossessedPlayer.RotationDegrees.y, 360, 4)); Vector3 Position = Base.Translation + (new Vector3(0, 6, 6)).Rotated(new Vector3(0, 1, 0), Rotation); return(new Vector3(Mathf.Round(Position.x), Mathf.Round(Position.y), Mathf.Round(Position.z))); } case (Items.TYPE.SLOPE): { float RotationDegrees = LoopRotation(SnapToGrid(Game.PossessedPlayer.RotationDegrees.y, 360, 4)); if (RotationDegrees != LoopRotation((float)Round(Base.RotationDegrees.y)) && LoopRotation(RotationDegrees + 180) != LoopRotation((float)Round(Base.RotationDegrees.y))) { return(null); } Vector3 Position; if (RotationDegrees == LoopRotation((float)Round(Base.RotationDegrees.y))) { Position = Base.Translation + (new Vector3(0, 12, 6)).Rotated(new Vector3(0, 1, 0), Mathf.Deg2Rad(RotationDegrees)); } else { Position = Base.Translation + (new Vector3(0, 0, 6)).Rotated(new Vector3(0, 1, 0), Mathf.Deg2Rad(RotationDegrees)); } return(new Vector3(Mathf.Round(Position.x), Mathf.Round(Position.y), Mathf.Round(Position.z))); } default: return(null); } }
public int[] CalculateI(float[] q) { Position p0 = new Position(new Vector3(0, 0, l1), new Quat(Vector3.Back, 0)); Position p1 = new Position(new Vector3(Controller.p2, 0, 0), new Quat(Vector3.Up, Mathf.Deg2Rad(q[1]))); Position p2 = new Position(new Vector3(0, 0, l2), new Quat(Vector3.Up, Mathf.Deg2Rad(q[2]))); Position p3 = new Position(new Vector3(l3, 0, Controller.p3), new Quat(Vector3.Right, 0)); Position r = p0 * p1 * p2 * p3; int[] result = { 1, 1, 1 }; if (r.pos.x < 0) { result[0] *= -1; } float q3a = 0.5f * Mathf.Pi - Mathf.Atan2(Controller.l3, Controller.p3); q3a = Mathf.Rad2Deg(q3a); if ((q[2] + 90 - q3a) * result[0] < 0) { result[1] *= -1; } if (q[4] < 0) { result[2] *= -1; } return(result); }
public override void _Input(InputEvent @event) { if (Input.GetMouseMode() != Input.MouseMode.Captured) { return; } if (@event is InputEventMouseMotion _motion) { // Tps var rotation = RotationDegrees; rotation.y -= _motion.Relative.x * 0.3f; RotationDegrees = rotation; var rotation2 = _cameraPivot.RotationDegrees; rotation2.x -= _motion.Relative.y * 0.3f; rotation2.x = Mathf.Clamp(rotation2.x, -50, 50); _cameraPivot.RotationDegrees = rotation2; // Fps // _head.RotateY(Mathf.Deg2Rad(-_motion.Relative.x * 0.3f)); var xDelta = _motion.Relative.y * 0.3f; if (_cameraFps.RotationDegrees.x - xDelta > -50 && _cameraFps.RotationDegrees.x - xDelta < 50) { _cameraFps.RotateX(Mathf.Deg2Rad(-xDelta)); } } }
//Camera movement/Pause start public override void _Input(InputEvent @event) { //Changes camera and rotation values depending on mouse movement if (@event is InputEventMouseMotion && Input.GetMouseMode() == Input.MouseMode.Captured) { InputEventMouseMotion mouseEvent = @event as InputEventMouseMotion; head_.RotateX(Mathf.Deg2Rad(-mouseEvent.Relative.y * MouseSenstivity)); RotateY(Mathf.Deg2Rad(-mouseEvent.Relative.x * MouseSenstivity)); } //Changes mouse mode if (Input.IsActionJustPressed("ui_cancel")) { if (Input.GetMouseMode() == Input.MouseMode.Captured) { Input.SetMouseMode(Input.MouseMode.Visible); } else { Input.SetMouseMode(Input.MouseMode.Captured); } } //Clamps the head x rotation to -90 and 90 Vector3 HeadRotation = head_.RotationDegrees; HeadRotation.x = Mathf.Clamp(head_.RotationDegrees.x, -90, 90); head_.RotationDegrees = HeadRotation; }
public override void _Input(InputEvent @event) { if (@event is InputEventMouseMotion) { var e = @event as InputEventMouseMotion; RotateY(-Mathf.Deg2Rad(e.Relative.x * MouseSensitivity)); _head.RotateX(-Mathf.Deg2Rad(e.Relative.y * MouseSensitivity)); var rotX = Mathf.Clamp(_head.Rotation.x, -2f, 2f); _head.Rotation = new Vector3(rotX, _head.Rotation.y, _head.Rotation.z); } if (Input.IsActionJustPressed("ToggleFlashlight")) { _flashlight.Visible = !_flashlight.Visible; } if (Input.IsActionJustPressed("ui_cancel")) { if (Input.GetMouseMode() == Input.MouseMode.Captured) { Input.SetMouseMode(Input.MouseMode.Visible); _settingsPage.Visible = true; } else { Input.SetMouseMode(Input.MouseMode.Captured); _settingsPage.Visible = false; } } if (Input.IsActionJustPressed("Crouch")) { IsCrouching = !IsCrouching; } // Movement Logic Vector3 directionVector = new Vector3(); Basis headBasis = _head.GlobalTransform.basis; if (Input.IsActionPressed("MoveForward")) { directionVector -= headBasis.z; } if (Input.IsActionPressed("MoveBackward")) { directionVector += headBasis.z; } if (Input.IsActionPressed("MoveLeft")) { directionVector -= headBasis.x; } if (Input.IsActionPressed("MoveRight")) { directionVector += headBasis.x; } Velocity = directionVector.Normalized() * Speed; }
public static void DrawSprite( Sprite sprite, Vector2 position, int subimage = 0, Vector2?scale = null, float rotation = 0f, Color?color = null, bool flipX = false, bool flipY = false) { if (sprite == null) { return; } if (sprite.Cols <= 0 || sprite.Rows <= 0) { return; } int width = sprite.Width; int height = sprite.Height; int row = (int)((subimage % sprite.SubimageCount) / (float)sprite.Cols); int column = (subimage % sprite.SubimageCount) % sprite.Cols; Rectangle sourceRectangle = new Rectangle(width * column + sprite.HOffset, height * row + sprite.VOffset, width, height); if (sourceRectangle.X + sourceRectangle.Width > sprite.Texture.Width || sourceRectangle.Y + sourceRectangle.Height > sprite.Texture.Height || sourceRectangle.X < 0f || sourceRectangle.Y < 0f) { return; } Vector2 fscale = scale ?? Vector2.One; Color fcolor = color ?? Color.White; SpriteEffects effects = SpriteEffects.None; if (flipX) { effects = effects | SpriteEffects.FlipHorizontally; } if (flipY) { effects = effects | SpriteEffects.FlipVertically; } //new Vector2(Mathf.Floor(position.X), Mathf.Floor(position.Y)) SpriteBatch.Draw( sprite.Texture, position, sourceRectangle, fcolor, Mathf.Deg2Rad(rotation), sprite.Origin, fscale, effects, 0f); }
public override void _Input(InputEvent @event) { Input.SetMouseMode(Input.MouseMode.Captured); if (@event is InputEventMouseMotion EventMouseMotion) { camBase.RotateY(Mathf.Deg2Rad(-EventMouseMotion.Relative.x * MOUSE_SENSITIVITY)); var viewChange = EventMouseMotion.Relative.y * MOUSE_SENSITIVITY; if (viewChange + viewAngle < 45 && viewChange + viewAngle > -90) { camBase2.RotateX(Mathf.Deg2Rad(viewChange)); viewAngle += viewChange; } } if (Input.IsActionJustPressed("ESC")) { GetTree().Quit(); } if (Input.IsActionJustPressed("R")) { GetTree().ReloadCurrentScene(); } }
private static bool BisectorSegment(Plan.Vertex vertex, Vector2 segmentA, Vector2 segmentB, out float offset) { IntersectionRaySegment2 intersection; if (Intersect.RaySegment(vertex.position, vertex.bisector, segmentA, segmentB, out intersection)) { if (intersection.type == IntersectionType.Point) { Vector2 segmentDirection = (segmentB - segmentA).Normalized(); float toIntersection = vertex.position.DistanceTo(intersection.pointA); float intersectionAngle = vertex.bisector.AngleTo(segmentDirection); float intersectionSin = Mathf.Sin(Mathf.Deg2Rad(intersectionAngle)); float bisectorSin = Geometry.GetAngleBisectorSin(vertex.angle); offset = toIntersection / (1 / intersectionSin + 1 / bisectorSin); return(true); } // BEGIN: Modified by Microsoft Corporation for generic logging purposes. API.MREAPI.Logger.LogError(string.Format("Invalid bisector intersection\ntype: {0}\npointA: {1} pointB: {2}\nray: {3} segmentA:{4} segmentB:{5}", intersection.type, intersection.pointA, intersection.pointB, vertex.bisector, segmentA, segmentB)); // END: Modified by Microsoft Corporation for generic logging purposes. offset = 0; return(false); } offset = 0; return(false); }
/// <summary>Get point C.</summary> /// <returns>Point.</returns> public Vector2 KochC() { var o = Start; var v = (End - Start) / 3; return(o + v + v.Rotated(-Mathf.Deg2Rad(60))); }
private Vector2 DirectionalVector(Vector2 vector, int _directions, float simmetry_angle) { float s_angle = Mathf.Deg2Rad(simmetry_angle); float angel = (vector.Angle() + s_angle) / (Mathf.Pi / _directions); if (angel >= 0) { angel = Mathf.Floor(angel); } else { angel = Mathf.Ceil(angel); } if ((Mathf.Abs(angel) % 2) == 1) { if (angel >= 0) { angel += 1; } else { angel -= 1; } } angel *= Mathf.Pi / _directions; angel -= s_angle; Vector2 directions = new Vector2(Mathf.Cos(angel), Mathf.Sin(angel)); return(directions * vector.Length()); }
public override void _UnhandledInput(InputEvent ev) { // When pressing escape and mouse is currently captured, release it. if (ev.IsActionPressed("ui_cancel") && Input.GetMouseMode() == Input.MouseMode.Captured) { Input.SetMouseMode(Input.MouseMode.Visible); } // Grab the mouse when pressing the primary mouse button. // TODO: Make "primary mouse button" configurable. if (ev is InputEventMouseButton button && button.ButtonIndex == (int)ButtonList.Left) { Input.SetMouseMode(Input.MouseMode.Captured); } if (ev is InputEventMouseMotion motion && Input.GetMouseMode() == Input.MouseMode.Captured) { _camera.RotateX(Mathf.Deg2Rad(motion.Relative.y * -MouseSensitivity)); _rotation.RotateY(Mathf.Deg2Rad(motion.Relative.x * -MouseSensitivity)); var rotation = _camera.RotationDegrees; rotation.x = Mathf.Clamp(rotation.x, -80, 80); _camera.RotationDegrees = rotation; } }
public override void _Ready() { Camera = GetNode <Camera>("Rotation_Helper/Camera"); _rotationalHelper = GetNode <Spatial>("Rotation_Helper"); AnimationManager = GetNode <AnimationPlayerManager>("Rotation_Helper/Model/Animation_Player"); AnimationManager.CallbackFunction = FireBullet; Input.SetMouseMode(Input.MouseMode.Captured); _weapons["KNIFE"] = GetNode <WeaponKnife>("Rotation_Helper/Gun_Fire_Points/Knife_Point"); _weapons["RIFLE"] = GetNode <WeaponRifle>("Rotation_Helper/Gun_Fire_Points/Rifle_Point"); _weapons["PISTOL"] = GetNode <WeaponPistol>("Rotation_Helper/Gun_Fire_Points/Pistol_Point"); var gunAimPointPos = GetNode <Spatial>("Rotation_Helper/Gun_Aim_Point").GlobalTransform.origin; foreach (var weapon in _weapons.Values) { if (weapon != null) { weapon.PlayerNode = this; weapon.LookAt(gunAimPointPos, Vector3.Up); weapon.RotateObjectLocal(Vector3.Up, Mathf.Deg2Rad(180)); } } _currentWeaponName = "UNARMED"; _changingWeaponName = "UNARMED"; _uiStatusLabel = GetNode <Label>("HUD/Panel/Gun_label"); _flashLight = GetNode <SpotLight>("Rotation_Helper/Flashlight"); }
public void FireWeapon(Destroyable target, Weapon weapon) { if (weapon == Weapon.Missile && CanMissileFire) { Missile missile1 = (Missile)MissileScene.Instance(); missile1.Homing = MissileHoming; missile1.Target = target; missile1.GlobalRotation = GlobalRotation; missile1.Position = GlobalPosition; missile1.Position += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90)); missile1.Velocity = Velocity; missile1.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90)), ProjectileEjectionForce); GetParent().AddChild(missile1); Missile missile2 = (Missile)MissileScene.Instance(); missile2.Homing = MissileHoming; missile2.Target = target; missile2.GlobalRotation = GlobalRotation; missile2.Position = GlobalPosition; missile2.Position += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90)); missile2.Velocity = Velocity; missile2.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90)), ProjectileEjectionForce); GetParent().AddChild(missile2); CanMissileFire = false; missileCooldownTimer.Start(MissileCooldown); } else if (weapon == Weapon.Laser && CanLaserFire) { if (target is SpaceDamagable damagable) { beam.AddPoint(target.GlobalPosition - GlobalPosition); damagable.Hit(); CanLaserFire = false; laserCooldownTimer.Start(LaserCooldown); } } else if (weapon == Weapon.Railgun && CanRailgunFire) { Rail rail = (Rail)RailScene.Instance(); rail.PartialHoming = RailHoming; rail.Velocity = Velocity; if (target != null) { rail.Target = target; rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition()); rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce); } else { rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition()); rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce); } rail.Position = GlobalPosition; GetParent().AddChild(rail); CanRailgunFire = false; railgunCooldownTimer.Start(RailgunCooldown); } }
private void ProcessMovement(float delta) { _dir.y = 0; _dir = _dir.Normalized(); _vel.y += delta * Gravity; Vector3 hvel = _vel; hvel.y = 0; Vector3 target = _dir; target *= MaxSpeed; float accel; if (_dir.Dot(hvel) > 0) { accel = Accel; } else { accel = Deaccel; } hvel = hvel.LinearInterpolate(target, accel * delta); _vel.x = hvel.x; _vel.z = hvel.z; _vel = MoveAndSlide(_vel, new Vector3(0, 1, 0), false, 4, Mathf.Deg2Rad(MaxSlopeAngle)); }
public override void _Process(float delta) { Vector2 CursorPos = GetLocalMousePosition(); Rotation += CursorPos.Angle() + StartRot; Rotation = Mathf.Wrap(Rotation, Mathf.Deg2Rad(-360), Mathf.Deg2Rad(360)); }
public override void Update(float delta) { if (rotating) { float amount = 0; leaningTime += delta * 2; if (leaning) { if (leanRight) { amount = Mathf.Lerp(0, -rotationAmount, leaningTime) - currentRotation; } else { amount = Mathf.Lerp(0, rotationAmount, leaningTime) - currentRotation; } } else { amount = Mathf.Lerp(rotatingFrom, 0, leaningTime) - currentRotation; } currentRotation += amount; controller.camera.RotateObjectLocal(controller.camera.Transform.basis.z, Mathf.Deg2Rad(amount)); if (leaningTime > 1) { rotating = false; } } }
override protected void StageTwoPhysicsProcess(float delta) { if (!_stageOne) { // grenade rises from current location if (_destination.y - this.Translation.y > 1f) { Vector3 motion = _direction * _speed * delta; this.MoveAndCollide(motion); } else { _lastFired += delta; // grenade rotates this.RotateY(Mathf.Deg2Rad(_rotationSpeed * delta)); // once grenade at destination, grenade fires nails for lifetime if (_lastFired >= _nailCooldown) { PackedScene nailScene = (PackedScene)ResourceLoader.Load(_projectileResource); Projectile nail = (Projectile)nailScene.Instance(); _playerOwner.MainNode.AddChild(nail); Transform t = _nailSpawn.GetGlobalTransform(); nail.Init(t, t.origin + (_nailSpawnLocation * 1000), _playerOwner, null, "nailgrenadenail", 0, 40, 30); } } } }
public void PhysicsMove(float delta, ref Vector3 velocity, Vector2 moveVec, Basis moveBasis, bool sprinting = false, bool jump = false) { var moveVelocity = Vector3.Zero; moveVelocity += moveBasis.x.Normalized() * moveVec.x; moveVelocity += moveBasis.z.Normalized() * moveVec.y; moveVelocity.y = 0; moveVelocity = moveVelocity.Normalized() * (sprinting ? SPRINT_SPEED : MOVE_SPEED); var hVelocity = velocity; hVelocity.y = 0; var accel = (moveVelocity.Dot(hVelocity) > 0) ? (body.IsOnWall() ? ACCELERATION_WALL : ACCELERATION) : DECELERATION; hVelocity = hVelocity.LinearInterpolate(moveVelocity, accel * delta); if (body.IsOnFloor() && jump) { velocity.y = JUMP_SPEED; } velocity.y += GRAVITY * delta; velocity.x = hVelocity.x; velocity.z = hVelocity.z; velocity = body.MoveAndSlide(velocity, Vector3.Up, 0.05f, 4, Mathf.Deg2Rad(20)); }
// // Called every frame. 'delta' is the elapsed time since the previous frame. // public override void _Process(float delta) // { // // } public override void _Input(InputEvent @event) { if (@event is InputEventMouseMotion movimientoMouse) { this.RotateY(Mathf.Deg2Rad(movimientoMouse.Relative.x)); } }
public override void OnBegin() { float Dir = _Direction.Evaluate(); DirectionVector = new Vector2(Mathf.Cos(Mathf.Deg2Rad(Dir)), Mathf.Sin(Mathf.Deg2Rad(Dir))); Timer = _Duration.Evaluate(); }
public void DrawBatch(Particle[] particles) { InitMultiMeshIfNeeded(); foreach (Particle p in particles) { if (p.alive) { Transform2D t = new Transform2D(); t.origin = p.position; t.x = Vector2.Right.Rotated(Mathf.Deg2Rad(p.rotation)) * p.size; t.y = Vector2.Up.Rotated(Mathf.Deg2Rad(p.rotation)) * p.size; multimesh.SetInstanceTransform2d(p.idx, t); multimesh.SetInstanceColor(p.idx, p.color); } else { multimesh.SetInstanceTransform2d(p.idx, ZERO_TRANSFORM); } } particleSystem.DrawRect(new Rect2(Vector2.Zero, Vector2.Zero), Colors.White); // Fixes weird mesh color particleSystem.DrawMultimesh(multimesh, tex, normalMap); }
// Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(float delta) { if (Input.IsActionPressed("ui_right")) { TranslateObjectLocal(Transform.basis.x * moveSpeed * delta); } if (Input.IsActionPressed("ui_left")) { TranslateObjectLocal(-Transform.basis.x * moveSpeed * delta); } if (Input.IsActionPressed("ui_up")) { TranslateObjectLocal(-Transform.basis.z * moveSpeed * delta); } if (Input.IsActionPressed("ui_down")) { TranslateObjectLocal(Transform.basis.z * moveSpeed * delta); } if (altIsPressed) { RotateY(Mathf.Deg2Rad(cameraHorizontalAngle) * mouseSpeed * delta); RotateX(Mathf.Deg2Rad(cameraVerticalAngle) * mouseSpeed * delta); } Transform.Orthonormalized(); }
public override void _Draw() { var center = RectSize / 2; var directions = parent.parent.JoystickDirections; var symmetryAngle = parent.parent.JoystickSymmetryAngle; DrawCircle(center, Radius, CircleColor); if (directions == 0) { // No lines return; } // Draw lines var angleAmount = 360 / directions; for (int i = 0; i < directions; i++) { var color = MainLinesColor; // Handle sub lines if (directions % 2 == 0 && directions > 4 && i % 2 == 1) { color = SubLinesColor; } DrawLine(center, center + (Vector2.Right * Radius).Rotated(-Mathf.Deg2Rad(symmetryAngle + (angleAmount * i))), color, LineWidth); } }
protected override void OnInitialize() { base.OnInitialize(); Input.SetMouseMode(Input.MouseMode.Visible); MovementInput .Where(_ => _modifierPressed) .Select(v => v * 0.05f) .Subscribe(v => _offset.y += v) .AddTo(this); this.OnInput() .Where(e => !e.IsEcho()) .Select(e => e.IsActionPressed(_controlModifier) || !e.IsActionReleased(_controlModifier) && _modifierPressed) .Subscribe(v => _modifierPressed = v) .AddTo(this); if (Pivot is IBounded bounded) { var bounds = bounded.Bounds; var fov = (Target as Camera)?.Fov ?? 70f; var height = bounds.GetLongestAxisSize(); var distance = height / 2f / Math.Tan(Mathf.Deg2Rad(fov / 2f)); Distance = (float)distance + 0.2f; } }
public override void _Process(float delta) { velocity = new Vector2(); if (Input.IsActionPressed("ui_right")) { velocity.x += 1; } if (Input.IsActionPressed("ui_left")) { velocity.x -= 1; } if (Input.IsActionPressed("ui_up")) { velocity.y -= 1; } if (Input.IsActionPressed("ui_down")) { velocity.y += 1; } if (velocity.Length() > 0) { velocity = velocity.Normalized() * SPEED; animatedSprite.Play(); particles.SetEmitting(true); } else { particles.SetEmitting(false); animatedSprite.Animation = "idle"; } Position += velocity * delta; Position = new Vector2( Mathf.Clamp(Position.x, 0, screenSize.x), Mathf.Clamp(Position.y, 0, screenSize.y) ); if (velocity.x != 0) { animatedSprite.Animation = "walk"; animatedSprite.FlipH = velocity.x < 0; animatedSprite.FlipV = false; colorSprite.Rotation = Mathf.Deg2Rad(45f); } else if (velocity.y != 0) { animatedSprite.Animation = "walk"; animatedSprite.FlipV = velocity.y > 0; if (velocity.y > 0) { colorSprite.Rotation = Mathf.Deg2Rad(225f); } else { colorSprite.Rotation = Mathf.Deg2Rad(45f); } } }
public override void _Input(InputEvent inputEvent) { if (inputEvent is InputEventKey key) { KeyboardAction(key); } if (inputEvent is InputEventMouseButton button) { if ((ButtonList)button.ButtonIndex == ButtonList.Right) { if (drag != true) { drag = true; } else { drag = false; } //MouseCameraControl(inputEvent); } } if (inputEvent is InputEventMouseMotion motion && drag) { //GlobalRotate(new Vector3(0,1,0), Mathf.Deg2Rad(motion.Relative.x*RotationSpeed)); RotateY(Mathf.Deg2Rad(motion.Relative.x * RotationSpeed)); } }