private void Update() { if (forceType == Forces.TorqueTest) { ApplyTorque(localSpace, new Vector2(-5, 0)); } if (forceType == Forces.Gravity) { AddForce(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass)); } else if (forceType == Forces.NormalForce) { AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1.0f, 0.0f).normalized)); } else if (forceType == Forces.SlidingForce) { AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1f, 1f).normalized))); } else if (forceType == Forces.StaticFriction) { Vector2 Normal = ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1.0f, 1.0f).normalized); AddForce(ForceGenerator.GenerateForce_friction_static(Normal, new Vector2(5, 5), 0.5f)); } else if (forceType == Forces.KinematicFriction) { AddForce(ForceGenerator.GenerateForce_friction_kinetic((ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1f, 1f).normalized)), new Vector2(1, 1), 0.5f)); } else if (forceType == Forces.Drag) { AddForce(ForceGenerator.GenerateForce_drag(new Vector2(1, 1), new Vector2(0.5f, 1), 1.0f, 2.0f, 0.2f)); } else if (forceType == Forces.Spring) { AddForce(ForceGenerator.GenerateForce_spring(position, new Vector2(0, -2), 10.0f, 1.0f)); } else if (forceType == Forces.Lab3Bonus) { Vector2 gravity = ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass); //AddForce(gravity); Vector2 Normal = ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1.0f, 1.0f).normalized); Vector2 Friction = ForceGenerator.GenerateForce_friction_kinetic((ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1f, 1f).normalized)), new Vector2(1, 1), 0.5f); //AddForce(Normal); AddForce(Friction); //ApplyTorque(localSpace, -Friction); ApplyTorque(localSpace, gravity); } }
// Update is called once per frame void Update() { applyTorque(); if (forcetype == forcegen.Gravity) { AddForce(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up)); } if (forcetype == forcegen.Normal) { AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit)); } if (forcetype == forcegen.Sliding) { AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit))); } if (forcetype == forcegen.Friction_Static) { AddForce(ForceGenerator.GenerateForce_Friction_Static(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit), f_opposing, frictionCoefficientStatic)); } if (forcetype == forcegen.Friction_Kinetic) { AddForce(ForceGenerator.GenerateForce_Friction_Kinetic(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit), velocity, frictionCoefficientKinetic)); } if (forcetype == forcegen.Drag) { AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit))); AddForce(ForceGenerator.GenerateForce_Drag(velocity, fluidVelocity, fluidDensity, objectAreaCrossSection, objectDragCoefficient)); } if (forcetype == forcegen.Spring) { //AddForce(ForceGenerator.GenerateForce_Spring(position, anchorPosition, springRestingLength,springStiffnessCoefficient)); AddForce(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up)); AddForce(ForceGenerator.GenerateForce_Spring(position, -position, springRestingLength, springStiffnessCoefficient)); } if (forcetype == forcegen.None) { } if (forcetype == forcegen.SphereRoll) { AddForce(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up)); AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit)); AddForce(ForceGenerator.GenerateForce_Friction_Static(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(Mass, kGravity, Vector2.up), surfaceNormalUnit), f_opposing, frictionCoefficientStatic)); } }
void UpdateForce() { // Lab 2 Step 3 //f_gravity = f = mg = ma Vector3 f_gravity = forces.mass * new Vector3(0.0f, -9.8f); Vector3 f_normal = ForceGenerator.GenerateForce_Normal(f_gravity, transform.up); // AddForce(f_gravity); // works if (forces.generateGravity) { AddForce(ForceGenerator.GenerateForce_Gravity(forces.mass, -9.8f, Vector3.up)); } if (forces.generateNormal) { AddForce(ForceGenerator.GenerateForce_Normal(f_gravity, forces.surfaceNormal_unit)); // works? more testing (surface normal is 0, 1) } if (forces.generateSliding) { AddForce(ForceGenerator.GenerateForce_Sliding(f_gravity, f_normal)); // (surface normal is 0,1) } if (forces.generateStaticsFriction) { AddForce(ForceGenerator.GenerateForce_Friction_Static(f_normal, forces.frictionOpposingForce, forces.frictionCoeff_static)); // works (surface normal is 1,1) FOF = (-3,0) FCS = 0.9 } if (forces.generateKineticFriction) { AddForce(ForceGenerator.GenerateForce_Friction_Kinetic(f_normal, particle3DTransform.velocity, forces.frictionCoeff_kinetic)); // works surface = (1,1) initVel = 15 FCK = 0.3 } if (forces.generateDrag) { AddForce(ForceGenerator.GenerateForce_Drag(particle3DTransform.velocity, forces.fluidVelocity, forces.fluidDensity, forces.objArea_CrossSection, forces.objDragCoeff)); // not sure if this works ask dan... IV = 1, FV = 1, FD = 1, OACS = 1.5, ODC=1.05 } if (forces.generateSpring && particle3DTransform.position.magnitude != 0) { AddForce(ForceGenerator.GenerateForce_Spring(particle3DTransform.position, forces.anchorPos, forces.springRestingLength, forces.springStiffnesCoeff)); // pos = 0,100 , AP = 0,0 , SRL = 0.1, SSC = 3 , fricCoKin = 0.15 (turn on gravity and kin fric } AddForce(forces.basicForce); }
// Update is called once per frame void FixedUpdate() { if (forceType == Forces.Gravity) { AddForce(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass)); } else if (forceType == Forces.NormalForce) { AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(5.0f, 0.0f).normalized)); } else if (forceType == Forces.SlidingForce) { AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1f, 1f).normalized))); } else if (forceType == Forces.StaticFriction) { Vector2 Normal = ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1.0f, 1.0f).normalized); AddForce(ForceGenerator.GenerateForce_friction_static(Normal, new Vector2(5, 5), 0.2f)); } else if (forceType == Forces.KinematicFriction) { AddForce(ForceGenerator.GenerateForce_friction_kinetic((ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(-10.0f, Vector2.up, mass), new Vector2(1f, 1f).normalized)), new Vector2(1, 1), 0.5f)); } else if (forceType == Forces.Drag) { AddForce(ForceGenerator.GenerateForce_drag(new Vector2(1, 1), new Vector2(0.5f, 1), 1.0f, 2.0f, 0.2f)); } else if (forceType == Forces.Spring) { AddForce(ForceGenerator.GenerateForce_spring(position, new Vector2(0, -2), 10.0f, 1.0f)); } //if Euler is selected in the drop down menu, do this if (calculationType == Physics.Euler) { UpdatePositionEulerExplicit(Time.fixedDeltaTime); transform.position = position; //set the new position UpdateRotationEulerExplicit(Time.fixedDeltaTime); transform.eulerAngles = new Vector3(0f, 0f, rotation); //set the new rotation //move cubes back and forth //acceleration.x = -Mathf.Sin(Time.time - startTime); } //if Kinematic is selected, do this else if (calculationType == Physics.Kinematic) { UpdatePositionKinematic(Time.fixedDeltaTime); transform.position = position; //set the new position UpdateRotationKinematic(Time.fixedDeltaTime); transform.eulerAngles = new Vector3(0f, 0f, rotation); //set the new rotation //move the cubes in a circle //acceleration.x = Mathf.Sin(Time.time - startTime); //acceleration.y = Mathf.Cos(Time.time - startTime); } UpdateAcceleration(); }
private void FixedUpdate() { switch (positionType) { case PosIntegrationType.EulerExplicit: UpdatePositionEulerExplicit(Time.fixedDeltaTime); break; default: UpdatePositionKinematic(Time.fixedDeltaTime); break; } switch (rotationType) { case RotIntegrationType.EulerExplicit: UpdateRotationEulerExplicit(Time.fixedDeltaTime); break; default: UpdateRotationKinematic(Time.fixedDeltaTime); break; } //lab03 UpdateAngularAcceleration(); UpdateAcceleration(); transform.position = position; Vector2 gravitationalForce = ForceGenerator.GenerateForce_Gravity(mass, -9.8f, Vector2.up); Vector2 normalForce = ForceGenerator.GenerateForce_Normal(-gravitationalForce, testFloor.transform.up); Vector2 slideForce = ForceGenerator.GenerateForce_Sliding(gravitationalForce, normalForce); Vector2 frictionForce = ForceGenerator.GenerateForce_Friction(normalForce, slideForce, velocity, frictionStatic, frictionKinetic); Vector2 dragForce = ForceGenerator.GenerateForce_Drag(velocity, new Vector2(0.2f, 0.0f), 10.0f, 10.0f, 4.0f); Vector2 springForce = ForceGenerator.GenerateForce_Spring(transform.position, testSpringAnchor.position, springRestingLength, springStrength * springStrength); Vector2 springDampForce = ForceGenerator.GenerateForce_SpringDamping(mass, velocity, springStrength, 5.0f); Vector2 springMaxLengthForce = ForceGenerator.GenerateForce_SpringWithMax(transform.position, testSpringAnchor.position, springRestingLength, springStrength * springStrength, maxSpringLength); switch (forceType) { case ForceType.gravity: AddForce(gravitationalForce); break; case ForceType.normal: AddForce(normalForce); break; case ForceType.slide: AddForce(slideForce); break; case ForceType.friction: AddForce(slideForce); AddForce(frictionForce); break; case ForceType.drag: AddForce(dragForce); break; case ForceType.spring: AddForce(springForce); break; case ForceType.springDamping: AddForce(springForce); AddForce(springDampForce); AddForce(gravitationalForce); break; case ForceType.springWithMaxLength: AddForce(springMaxLengthForce); AddForce(springDampForce); AddForce(gravitationalForce); break; case ForceType.none: //Debug.Log("We ain't movin chief."); break; default: AddForce(gravitationalForce); break; } //lab03 ApplyTorque(pointApplied, forceApplied); //clamps rotation to 360 SetRotation(rotation %= 360.0f); rotAcceleration = angularAccel; }
/* * Lab 1 * Integrate user friendly menu. */ // Get selectable items from the inspector menu. private void GetInspectorItems() { /* * Lab 1 Step 3 */ // Integrate. if (positionType == PositionType.Euler) { UpdatePositionEulerExplicit(Time.fixedDeltaTime); } else if (positionType == PositionType.Kinematic) { UpdatePositionKinematic(Time.fixedDeltaTime); } if (rotationType == RotationType.Euler) { UpdateRotationEulerExplicit(Time.fixedDeltaTime); } else if (rotationType == RotationType.Kinematic) { UpdateRotationKinematic(Time.fixedDeltaTime); } if (gravityActive) { // Gravity force. AddForce(ForceGenerator.GenerateForce_Gravity(mass, GRAVITY, Vector2.up)); } if (springActive) { // Spring force. AddForce(ForceGenerator.GenerateForce_Spring(springAnchor.position, transform.position, springRestLength, springStiffness)); } if (staticFrictionActive) { // Static friction force. AddForce(ForceGenerator.GenerateForce_Friction_Static(staticFrictionNormal, staticFrictionOpposingForce, staticFrictionCoefficient)); } if (kinematicFrictionActive) { // Kinematic friction force. AddForce(ForceGenerator.GenerateForce_Friction_Kinetic(kinematicNormalForce, velocity, kinematicFrictionCoefficient)); } if (slidingActive) { // Sliding force. AddForce(ForceGenerator.GenerateForce_Sliding(ForceGenerator.GenerateForce_Gravity(mass, GRAVITY, worldUp), slidingNormalForce)); } if (dragActive) { // Drag force. AddForce(ForceGenerator.GenerateForce_Drag(velocity, fluidVelocity, fluidDensity, objectCrossSection, dragCoefficient)); } if (normalActive) { // Normal force. AddForce(ForceGenerator.GenerateForce_Normal(ForceGenerator.GenerateForce_Gravity(mass, GRAVITY, worldUp), surfaceNormal)); } if (dampingSpringActive) { // Damping spring force. AddForce(ForceGenerator.GenerateForce_Spring_Damping(position, springAnchor.position, springRestLength, springStiffness, springDamping, springConstant, velocity)); } return; }