List <Vector2> PredictPath(int numberofpoints) { List <Vector2> points = new List <Vector2>(); Vector2 lastposition = rb.position + (velocitytoshoot.normalized * shooterradius * 2); float dt = 0.03f; points.Add(lastposition); Vector2 acceleration = Attractor.FieldAtPoint(lastposition); Vector2 position = lastposition + velocitytoshoot * dt + (0.5f * acceleration * Mathf.Pow(dt, 2)); points.Add(position); Vector2 nextposition = new Vector2(0, 0); for (int i = 2; i < numberofpoints; i++) { acceleration = Attractor.FieldAtPoint(position); nextposition = 2 * position - lastposition + acceleration * Mathf.Pow(dt, 2); points.Add(nextposition); lastposition = position; position = nextposition; } return(points); }
private void Attract(Attractor objToAttract, bool towards) { Rigidbody rbToAttract = objToAttract.rb; if (rbToAttract == null) { return; } Vector3 direction = new Vector3(); if (towards) { direction = rb.position - rbToAttract.position; } else { direction = rbToAttract.position - rb.position; } float distance = direction.magnitude; if (distance <= 0.1f) { return; } float forceMagnitude = G * (rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 2); Vector3 force = direction.normalized * forceMagnitude; rbToAttract.AddForce(force); }
public ParticleEffect(int apiVersion, EventHandler handler, ISection section) : base(apiVersion, handler, section) { mParticleParameters = new ParticleParams(apiVersion, handler, true); mRateCurve = new DataList <FloatValue>(handler); mSizeCurve = new DataList <FloatValue>(handler); mAspectCurve = new DataList <FloatValue>(handler); mRotationCurve = new DataList <FloatValue>(handler); mAlphaCurve = new DataList <FloatValue>(handler); mColorCurve = new DataList <ColorValue>(handler); mColorVary = new ColorValue(apiVersion, handler); mDrawInfo = new ResourceReference(apiVersion, handler, section); mDirectionalForcesSum = new Vector3ValueLE(apiVersion, handler); mRadialForceLocation = new Vector3ValueLE(apiVersion, handler); mWiggles = new DataList <Wiggle>(handler); mLoopBoxColorCurve = new DataList <ColorValue>(handler); mLoopBoxAlphaCurve = new DataList <FloatValue>(handler); mSurfaces = new DataList <Surface>(handler); mAltitudeRange = new Vector2ValueLE(apiVersion, handler, -10000.0f, 10000.0f); mRandomWalk = new RandomWalk(apiVersion, handler); mAttractorOrigin = new Vector3ValueLE(apiVersion, handler); mAttractor = new Attractor(apiVersion, handler); mPathPoints = new DataList <PathPoint>(handler); mVector01 = new Vector3ValueLE(apiVersion, handler); mVector3List01 = new DataList <Vector3ValueLE>(handler); mVector02 = new Vector3ValueLE(apiVersion, handler); mUnknown140 = new Vector2ValueLE(apiVersion, handler); mUnknown150 = new Vector2ValueLE(apiVersion, handler); mUnknown180 = new Vector3ValueLE(apiVersion, handler); mUnknown190 = new Vector2ValueLE(apiVersion, handler); mUnknown1A0 = new Vector2ValueLE(apiVersion, handler); }
void Attract(Attractor obj) { Rigidbody rbToAttract = obj.rb; Vector3 direction = rb.position - rbToAttract.position; float distance = direction.magnitude; if (distance > maxDistance) { return; } if (distance < 5) { GiveEnergyByDistance(distance); } distance = Mathf.Clamp(distance, 0, 10); float forceMagnitude = 0; if (distance < 5) { distance = 5; } forceMagnitude = G * (rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 1f); Vector3 force = direction.normalized * forceMagnitude; rbToAttract.AddForce(force); }
private void checkForSnapPosition(Vector2 screenPosition, ObjectManipulationInputController.Cancelable cancelable) { Ray ray = Camera.main.ScreenPointToRay(screenPosition); RaycastHit[] array = Physics.RaycastAll(ray, float.PositiveInfinity, LayerMask.GetMask(LayerMask.LayerToName(base.gameObject.layer)), QueryTriggerInteraction.Collide); for (int i = 0; i < array.Length; i++) { Attractor component = array[i].transform.GetComponent <Attractor>(); if (!(component != null) || !attractors.Contains(component)) { continue; } cancelable.Cancel(); if (!snapped) { if (this.OnAttracted != null) { this.OnAttracted(this, component.GetComponent <Collider>(), trackedObject, base.transform.rotation); } snapped = true; } return; } if (snapped) { snapped = false; this.OnUnSnapped.InvokeSafe(this, trackedObject); } }
void Attract(Attractor objToAttract) { Rigidbody2D rbToAttract = objToAttract.rb; if (orbitSpeed == 0f) { orbitSpeed = rbToAttract.velocity.magnitude; } Vector2 direction = rb.position - rbToAttract.position; float distance = direction.magnitude; //Debug.Log(distance); float forceMagnitude = (rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 2); Vector2 force = direction.normalized * forceMagnitude; if (this.GetComponent <Player>() != null) { if (distance > this.GetComponent <Player>().OrbitRange&& objToAttract.gameObject.layer != 9) { rbToAttract.AddForce(force); } else if (this.GetComponent <Player>().orbit == true && objToAttract.gameObject.layer != 11 && objToAttract.gameObject.GetComponent <Attractor>().hasBeenInOrbit != true) { objToAttract.gameObject.layer = 9; objToAttract.gameObject.transform.SetParent(transform); Transform trns = objToAttract.transform; Orbit(trns, orbitSpeed); rbToAttract.velocity = new Vector2(0f, 0f); } else if (objToAttract.gameObject.layer == 9) { AfterOrbit(rbToAttract, orbitSpeed); } } }
public static void CalculateBothPrediction() { if (BothAttr == null || BothAttr.Count == 0 || BothAttr[0].validPrediction) { return; } for (int i = 0; i < numPre; i += stepInc) { for (int j = 0; j < BothAttr.Count; ++j) { //calculate prediction step including the movement of attractor objects if (i == 0) { BothAttr[j].calc_pos = BothAttr[j].transform.position; BothAttr[j].calc_vel = BothAttr[j].rb.velocity; BothAttr[j].prediction.Clear(); BothAttr[j].validPrediction = true; BothAttr[j].stepsSinceLastPrediction = 0; } AttractorReturn force = Attractor.getFutureAttractionVectorSteps(BothAttr[j], BothAttr[j].calc_pos, i); BothAttr[j].calc_vel += (force.force / BothAttr[j].rb.mass) * (Time.fixedDeltaTime * stepInc); BothAttr[j].calc_pos += BothAttr[j].calc_vel * (Time.fixedDeltaTime * stepInc); BothAttr[j].prediction.Add(new PredictionStep(BothAttr[j].calc_pos, BothAttr[j].calc_vel, force.strongest)); } } }
// Use this for initialization void Start() { rb = GetComponent<Rigidbody>(); Core = FindObjectOfType<Attractor>(); radius = Vector3.Distance(rb.position, Core.GetComponent<Transform>().position); rb.velocity = transform.TransformDirection(new Vector3(enemyShotVelocityX, enemyShotVelocityY, 0)); }
public MetaparticleEffect(int apiVersion, EventHandler handler, ISection section) : base(apiVersion, handler, section) { mParticleParameters = new ParticleParams(apiVersion, handler, true); mRateCurve = new DataList <FloatValue>(handler); mSizeCurve = new DataList <FloatValue>(handler); mPitchCurve = new DataList <FloatValue>(handler); mRollCurve = new DataList <FloatValue>(handler); mHeadingCurve = new DataList <FloatValue>(handler); mRollOffset = -1000000000.0f; mHeadingOffset = 0f; mColorCurve = new DataList <ColorValue>(handler); mColorVary = new ColorValue(apiVersion, handler); mAlphaCurve = new DataList <FloatValue>(handler); mDirectionalForcesSum = new Vector3ValueLE(apiVersion, handler); mGlobalForcesSum = new Vector3ValueLE(apiVersion, handler); mRadialForceLocation = new Vector3ValueLE(apiVersion, handler); mWiggles = new DataList <Wiggle>(handler); mLoopBoxColorCurve = new DataList <ColorValue>(handler); mLoopBoxAlphaCurve = new DataList <FloatValue>(handler); mSurfaces = new DataList <Surface>(handler); mAltitudeRange = new Vector2ValueLE(apiVersion, handler, -10000.0f, 10000.0f); mRandomWalk1 = new RandomWalk(apiVersion, handler); mRandomWalk2 = new RandomWalk(apiVersion, handler); mRandomWalkPreferredDirection = new Vector3ValueLE(apiVersion, handler); mAttractorOrigin = new Vector3ValueLE(apiVersion, handler); mAttractor = new Attractor(apiVersion, handler); mPathPoints = new DataList <PathPoint>(handler); }
private void Start() { rb = GetComponent <Rigidbody>(); rb.constraints = RigidbodyConstraints.FreezeRotation; rb.useGravity = false; attractor = GameObject.FindWithTag("World").GetComponent <Attractor>(); }
public static Attractor[] CreateAttractors(Graph graph, IEnumerable <AttractorObject> attractorObjects) { var attractors = new List <Attractor>(); foreach (var attrObj in attractorObjects) { Node closest = graph.GetClosestNode((float)attrObj.Position.X, (float)attrObj.Position.Y); if (closest == null) { throw new ArgumentException("Graph has no nodes"); } if (attractors.Exists(a => a.Node == closest)) { continue; } var attractor = new Attractor { Node = closest, WorkingRadius = attrObj.WorkingRadius, Performance = AttractorPerformanceToNumber(attrObj.Performance), IsSource = attrObj.Type == AttractorType.Universal || attrObj.Type == AttractorType.Source, IsDrain = attrObj.Type == AttractorType.Universal || attrObj.Type == AttractorType.Drain }; attractors.Add(attractor); } return(attractors.ToArray()); }
void Attract(Attractor objToAttract) { if (isPlayer) { if (Input.GetKey(KeyCode.Space)) { mass = rb.mass * 10; } else { mass = rb.mass; } } else { mass = rb.mass; } Rigidbody2D rbToAttract = objToAttract.rb; Vector2 dir = rb.position - rbToAttract.position; float dist = dir.magnitude * 150.24f; float forceMag = (mass * rbToAttract.mass) / Mathf.Pow(dist, 2); Vector2 force = dir.normalized * forceMag * 20; rbToAttract.AddForce(force); }
private void DetachAttractor(Attractor attractor) { if (attractor != null && attractors.Contains(attractor)) { attractors.Remove(attractor); } }
void Attract(Attractor objToAttract) { Rigidbody rbToAttract = objToAttract.rb; Vector3 direction = rb.position - rbToAttract.position; float distance = direction.magnitude; if (distance == 0f) { return; } la = GameObject.Find("La"); if (la != null) { paresCargas = GameObject.Find("ParesCargas"); active_counter_script active_script = paresCargas.GetComponent <active_counter_script> (); eletrons = active_script.num_eletrons; } else { paresCargasAnti = GameObject.Find("ParesCargasAnti"); active_counter_script active_script = paresCargasAnti.GetComponent <active_counter_script>(); eletrons = active_script.num_eletrons; } multiplier = eletrons * CONSTANTE; float forceMagnitude = multiplier * ((rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 2)); Vector3 force = direction.normalized * forceMagnitude; rbToAttract.AddForce(force); }
void Attract(Attractor objToAttract) { // added this check because errors were getting thrown during scene reload if (this.rb == null || objToAttract == null) { return; } if (objToAttract.GetType() != typeof(Planet)) { return; } Rigidbody rbToAttract = objToAttract.rb; Vector3 direction = rb.position - rbToAttract.position; float distance = direction.magnitude; if (distance == 0f) { return; } float forceMagnitude = G * (rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 1f); Vector3 force = direction.normalized * forceMagnitude; rbToAttract.AddForce(force); }
public override void OnInspectorGUI() { reference = this.target as Attractor; DrawDefaultInspector(); reference.radius = Mathf.Max(0, reference.radius); }
private void Attract(Attractor objToAttract) { Rigidbody rbToAttract = objToAttract.rb; Vector3 direction = rb.position - rbToAttract.position; float distance = direction.magnitude; if (distance == 0f) { return; } float forceMagnitude = 0f; switch (GameplayManager.Instance.gameMod) { case GameMod.Hard: forceMagnitude = G * (rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 2); break; case GameMod.Easy: forceMagnitude = G * (rb.mass * rbToAttract.mass) * gravityStrenght / 100f; break; } Vector3 force = direction.normalized * forceMagnitude; rbToAttract.AddForce(force.x, rbToAttract.transform.position.y, force.z); }
Vector3 GetForce(List <Attractor> attractors) { Vector3 newVelocity = Vector3.zero; Attractor closestPlanet = attractors[0]; float minDistance = float.MaxValue; for (int attractToIndex = 0; attractToIndex < attractors.Count; attractToIndex++) { Attractor attractTo = attractors[attractToIndex]; float mass = attractTo.mass; //attractor.Rigidbody().mass * Vector3 direction = attractTo.Position() - rb.position; float distance = direction.magnitude; float forceMagnitude = UniverseConstants.NewtonsGravityConstant * (mass) / Mathf.Pow(distance, 2); newVelocity += direction.normalized * forceMagnitude; if (minDistance > distance) { closestPlanet = attractTo; } } Planet = closestPlanet; return(newVelocity); }
//get attraction vector for all objects public static AttractorReturn getAttractionVector(Attracted obj) { Vector2 totalForce = new Vector2(0, 0); if (attractors == null) { return(new AttractorReturn(new Vector2(0, 0), null)); } Attractor strongest = null; float strongestForce = 0; foreach (Attractor a in attractors) { if (obj.gameObject != a.gameObject) { Vector2 force = ((Vector2)a.transform.position - (Vector2)obj.transform.position).normalized; float forceMag = a.getAttractionForce(obj); force *= forceMag; totalForce += force; if (forceMag > strongestForce) { strongestForce = forceMag; strongest = a; } } } return(new AttractorReturn(totalForce, strongest)); }
public static AttractorReturn getFutureAttractionVectorSeconds(Attracted obj, Vector2 pos, float seconds) { Vector2 totalForce = new Vector2(0, 0); if (attractors == null) { return(new AttractorReturn(new Vector2(0, 0), null)); } Attractor strongest = null; float strongestForce = 0; foreach (Attractor a in attractors) { if (obj.gameObject != a.gameObject) { Vector2 force = (a.getPosInSeconds(seconds) - pos).normalized; float forceMag = a.getAttractionForceInFutureSeconds(pos, obj.rb.mass, seconds); force *= forceMag; totalForce += force; if (forceMag > strongestForce) { strongestForce = forceMag; strongest = a; } } } return(new AttractorReturn(totalForce, strongest)); }
private void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.tag == "Planet") { attractor = null; GetComponentInChildren <Jetpack>().jetpackspeed = 230; } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Planet") { attractor = collision.gameObject.GetComponent <Attractor>(); GetComponentInChildren <Jetpack>().jetpackspeed = 600; } }
// Start is called before the first frame update void Start() { grabbable = GetComponent <OVRGrabbable>(); attractor = GetComponent <Attractor>(); grabbable.OnGrabBegin += Grabbable_OnGrabBegin; grabbable.OnGrabEnd += Grabbable_OnGrabEnd; }
private void Awake() { attractor = GetComponent <Attractor>(); if (!attractor) { Debug.LogWarning("Attractor is NULL! Check the component!", this); } }
// Use this for initialization void Start() { startPlanet = GameObject.Find (PLANET_NAME); attractor = startPlanet.GetComponent<Attractor>(); GetComponent<Rigidbody> ().constraints = RigidbodyConstraints.FreezeRotation; GetComponent<Rigidbody> ().useGravity = false; myTransform = transform; }
void Awake() { controller = GetComponent <SpacecraftController>(); actions = new List <SpacecraftAction>(); rb = GetComponent <Rigidbody2D>(); attractor = GetComponent <Attractor>(); damageIndication = GetComponent <ActivateForTime>(); }
// Use this for initialization void Start() { startPlanet = GameObject.Find("Core"); attractor = startPlanet.GetComponent <Attractor>(); GetComponent <Rigidbody> ().constraints = RigidbodyConstraints.FreezeRotation; GetComponent <Rigidbody> ().useGravity = false; myTransform = transform; }
public void OnSceneGUI() { reference = this.target as Attractor; Handles.color = reference.forceType == ForceType.Attract ? Color.green : Color.red; Handles.DrawWireDisc(reference.transform.position, reference.transform.forward, reference.radius); }
public ARRT(Manipulator manipulator, int maxIterations, float threshold, bool collisionCheck, float step, bool showTree, bool enableTrimming, int trimPeriod, int attractorsCount) : base(maxIterations, threshold, collisionCheck, step, showTree, enableTrimming, trimPeriod) { _attractorsCount = attractorsCount; // create attractors _attractors = Attractor.Create(manipulator, _attractorsCount, _threshold); // TODO: if attractors count can be changed from the outside, // then the generation should happen on execution or like an event }
void Attract(Attractor objOther) { Rigidbody2D rbOther = objOther.rb; Vector2 direction = rb.position - rbOther.position; float distance = direction.magnitude; float forceMagnitude = G * (rb.mass * rbOther.mass) / Mathf.Pow(distance, 2); Vector2 force = direction.normalized * forceMagnitude; rbOther.AddForce(force); }
void Attract(Attractor objToAttract) { Rigidbody rbToAttract = objToAttract.rb; Vector3 direction = rb.position - rbToAttract.position; float distance = direction.magnitude; float forceMagnitude = (rb.mass * rbToAttract.mass) / Mathf.Pow(distance, 2); Vector3 force = direction.normalized * forceMagnitude; rbToAttract.AddForce(force); }
private void Attract(Attractor objectToAttract) { Rigidbody rbToAttract = objectToAttract.rb; Vector3 direction = transform.position - rbToAttract.transform.position; float distance = direction.magnitude; float forceMagnitude = GameController.Instance.Settings.G * (rb.mass * rbToAttract.mass) / Mathf.Pow(GameController.Instance.Settings.DistanceScaler * distance, 2); Vector3 force = direction.normalized * forceMagnitude; rbToAttract.AddForce(force); }
// Use this for initialization void Start() { Core = FindObjectOfType<Attractor>(); radius = Vector3.Distance(rb.position, Core.GetComponent<Transform>().position); rb = GetComponent<Rigidbody>(); theCharacterMotor = GetComponent<CharacterMotor2>(); if (theCharacterMotor.movingRight==true) { rb.velocity = transform.TransformDirection(new Vector3(enemyShotVelocityX, 0, 0)); shootingRight = true; } if (theCharacterMotor.movingLeft==true) { rb.velocity = transform.TransformDirection(new Vector3(-enemyShotVelocityX, 0, 0)); shootingRight = false; } }
public void removeAttractor(Attractor a) { attractors.Remove(a); }
// Use this for initialization void Start() { rb = GetComponent<Rigidbody>(); Core = FindObjectOfType<Attractor>(); radius = Vector3.Distance(rb.position, Core.GetComponent<Transform>().position); }
public void addAttractor(Attractor a) { attractors.Add(a); }
// Use this for initialization void Start() { base.Start(); // Shadowman-specific states this[EntityState.EXPANDING] = expand; this[EntityState.EXPELLING] = expelling; pController = player.gameObject.GetComponent(typeof(CharacterController)) as CharacterController; attr = new Attractor(transform, suckSpeed); }