private void FixedUpdate() { if (fuel > 0) { Vector3 p0 = car.transform.TransformPoint(new Vector3(LocalAnchorB.x, LocalAnchorB.y, -5f)); backBody.PhysicsBody.ApplyTorque(-movement * speed * Time.fixedDeltaTime); if (Input.GetKeyDown(KeyCode.Space)) { car.PhysicsBody.ApplyForce(jumpPow * FSHelper.Vector2ToFVector2(jumpForce), FSHelper.Vector3ToFVector2(p0)); } } else { StartCoroutine("OpenMenu"); } fuel -= fuelConsumption * Mathf.Abs(movement) * Time.fixedDeltaTime; if (Input.GetKey(KeyCode.K)) { car.PhysicsBody.ApplyTorque(-rotationPow * speed * Time.fixedDeltaTime); } if (Input.GetKey(KeyCode.J)) { car.PhysicsBody.ApplyTorque(rotationPow * speed * Time.fixedDeltaTime); } if (fuel <= 0) { Debug.Log("You have failed"); } }
public override void InitJoint() { base.InitJoint(); //B tekerlek //A araba //jesus %99 em-in Vector3 p0 = BodyB.transform.TransformPoint(new Vector3(LocalAnchorB.x, LocalAnchorB.y, -5f)); joint = JointFactory.CreateWheelJoint(FSWorldComponent.PhysicsWorld, BodyA.PhysicsBody, BodyB.PhysicsBody, BodyB.PhysicsBody.GetLocalPoint(FSHelper.Vector3ToFVector2(p0)), FSHelper.Vector2ToFVector2(axis)); //UnitY ile yanlış yapıyor olabilirim joint.MaxMotorTorque = MaxMotorTorque; joint.MotorEnabled = MotorEnabled; joint.MotorSpeed = MotorSpeed; joint.SpringDampingRatio = springDampingRatio; joint.SpringFrequencyHz = springFrequency; joint.CollideConnected = false; // }
public void ConvertToConvex() { FSShapeComponent[] childFsShapes = GetComponentsInChildren <FSShapeComponent>(); foreach (FSShapeComponent shapeComponent in childFsShapes) { if (shapeComponent.gameObject == null) { continue; } DestroyImmediate(shapeComponent.gameObject); } // convert vertices var concaveVertices = new FarseerPhysics.Common.Vertices(); if (PointInput == FSShapePointInput.Transform) { for (int i = 0; i < PointsTransforms.Length; i++) { concaveVertices.Add(FSHelper.Vector3ToFVector2(PointsTransforms[i].localPosition)); } } if (PointInput == FSShapePointInput.Vector2List) { foreach (var coordinate in PointsCoordinates) { concaveVertices.Add(FSHelper.Vector2ToFVector2(transform.TransformPoint(coordinate))); } } List <FarseerPhysics.Common.Vertices> convexShapeVs = FarseerPhysics.Common.Decomposition.BayazitDecomposer.ConvexPartition(concaveVertices); for (int i = 0; i < convexShapeVs.Count; i++) { var newConvShape = new GameObject("convexShape" + i.ToString()); newConvShape.transform.parent = transform; newConvShape.transform.localPosition = Vector3.zero; newConvShape.transform.localRotation = Quaternion.Euler(Vector3.zero); newConvShape.transform.localScale = Vector3.one; var shapeComponent = newConvShape.AddComponent <FSShapeComponent>(); shapeComponent.CollidesWith = CollidesWith; shapeComponent.CollisionFilter = CollisionFilter; shapeComponent.BelongsTo = BelongsTo; shapeComponent.CollisionGroup = CollisionGroup; shapeComponent.Friction = Friction; shapeComponent.Restitution = Restitution; shapeComponent.Density = Density; shapeComponent.UseUnityCollider = false; shapeComponent.UseTransforms = (PointInput == FSShapePointInput.Transform); if (PointInput == FSShapePointInput.Transform) { shapeComponent.PolygonTransforms = new Transform[convexShapeVs[i].Count]; for (int j = 0; j < convexShapeVs[i].Count; j++) { var pnew = new GameObject("p" + j.ToString(CultureInfo.InvariantCulture)); pnew.transform.parent = shapeComponent.transform; pnew.transform.localPosition = FSHelper.FVector2ToVector3(convexShapeVs[i][j]); shapeComponent.PolygonTransforms[j] = pnew.transform; } } else { shapeComponent.PolygonCoordinates = new Vector2[convexShapeVs[i].Count]; for (int j = 0; j < convexShapeVs[i].Count; j++) { shapeComponent.PolygonCoordinates[j] = newConvShape.transform.InverseTransformPoint(FSHelper.FVector2ToVector3(convexShapeVs[i][j])); } } } }
/// <summary> /// Sets the local anchor b at runtime. /// </summary> /// <param name='value'> /// Value. /// </param> public void SetLocalAnchorB(Vector2 value) { LocalAnchorB = value; joint.LocalAnchorB = FSHelper.Vector2ToFVector2(value); }