public void CreateProjectile(ProjectileSpawnParameters parameters) { _currentParameters = parameters; OnProjectileCreated?.Invoke(parameters); OnProjectileDefined?.Invoke(); OnProjectileInitialized?.Invoke(parameters); }
private void CastProjectile(ProjectileSpawnParameters parameters) { var prevQuery = Physics2D.queriesHitTriggers; Physics2D.queriesHitTriggers = false; var hit = Physics2D.RaycastAll(_position.Position, _velocity.Velocity, _velocity.Velocity.magnitude * _settings.baseRange, _layerMask); Physics2D.queriesHitTriggers = prevQuery; var startPos = _position.Position; Vector2 lastPos = _position.Position + _velocity.Velocity * _settings.baseRange; for (int i = 0; i < hit.Length; i++) { if (_pipeline.State == ProjectilePhases.Destroyed) { break; } _velocity.Velocity = Vector2.Reflect(_velocity.Velocity, hit[i].normal); _position.Position = hit[i].point; _colHandler.HandleCollision(hit[i].collider); lastPos = hit[i].point; } _position.Position = lastPos; if (_pipeline.State != ProjectilePhases.Destroyed) { _facade.Destroy(); //Destroy ray even if it did not hit anything } OnRayExecuted?.Invoke(startPos, lastPos); }
/// <summary> /// Creates projectile with current weapon at given position and with given rotation. /// </summary> /// <param name="position"></param> /// <param name="rotation"></param> /// <returns></returns> public bool Shoot(Vector2 position, float rotation) { if (_wasSqueezed == false && CanShootAtPosition(position)) { _wasSqueezed = true; var parameters = new ProjectileSpawnParameters(position, rotation, _settings.velocity, _settings.timeToLive, _modules, _inheritableModules, dummy: _info.IsLocal == false); Factory.Create(parameters); OnShoot?.Invoke(parameters); } return(true); }
private void OnProjectileDestroyed(ProjectilePipelineParameters param) { var velocity = param.projectile.Velocity; var baseRotation = velocity.Rotation(); var spawnPos = param.projectile.Position + Vector2.ClampMagnitude(velocity, Constants.COLLISION_CORRECTION_EPS); var spawnParam = new ProjectileSpawnParameters(spawnPos, baseRotation, velocity.magnitude, _settings.ttl, param.inheritableModules, param.inheritableModules, param.projectile.IsDummy); _factory.Create(spawnParam); spawnParam.rotation = baseRotation + _settings.spreadAngle; _factory.Create(spawnParam); spawnParam.rotation = baseRotation - _settings.spreadAngle; _factory.Create(spawnParam); }
private void OnShoot(ProjectileSpawnParameters obj) { if (_info.IsLocal) { using (var writer = DarkRiftWriter.Create()) { writer.Write(_info.Id); writer.Write(obj.position.x); writer.Write(obj.position.y); writer.Write(obj.rotation); using (var message = Message.Create(Tags.SpawnProjectile, writer)) { _client.SendMessage(message, SendMode.Reliable); } } } }
private void OnProjectileDestroyed(ProjectileSpawnParameters parameters) { _pipeline.SetState(ProjectilePhases.Destroyed, new ProjectilePipelineParameters(_facade, parameters)); }
private void OnProjectileInitialized(ProjectileSpawnParameters parameters) { _pipeline.SetState(ProjectilePhases.Created, new ProjectilePipelineParameters(_facade, parameters)); }
private void OnShoot(ProjectileSpawnParameters projectileSpawnParameters) { _soundProvider.PlayShootSound(); }
private void OnDestroyed(ProjectileSpawnParameters obj) { _factory.Create(_position.Position); }
public ProjectilePipelineParameters(IProjectile projectile, ProjectileSpawnParameters parameters) { this.projectile = projectile; this.modules = parameters.modules; this.inheritableModules = parameters.inheritableModules; }
private void OnCreated(ProjectileSpawnParameters obj) { IsDummy = obj.dummy; }
private void OnCreated(ProjectileSpawnParameters obj) { _ttl = obj.ttl; }
private void OnParticleCreated(ProjectileSpawnParameters parameters) { Position = parameters.position; Velocity = Vector2.up.Rotate(parameters.rotation) * parameters.velocity; }
private void ProjectileCreated(ProjectileSpawnParameters parameters) { SetModules(parameters.modules); InitModules(); }