Unconfigured Ad Widget

تقليص

إعـــــــلان

تقليص
لا يوجد إعلان حتى الآن.

الرجاء المساعدة

تقليص
X
 
  • تصفية - فلترة
  • الوقت
  • عرض
إلغاء تحديد الكل
مشاركات جديدة

  • الرجاء المساعدة

    السلام عليكم

    اخوان لدي مشروع صناعة لعبة سباق سيارت 3d باليونتي واحتاج المساعدة بأعطائي الاكواد الاتية

    1- كود يجعل الكامرة تتبع السيارة بأحتراف
    2- كود يجعل العجلات تدور عند المشي
    3- كود يجعل العجلات الامامية تدور بالاتجاهين يمين يسار
    4- كود البريك ( التوقف عند الضغط على زر spac )
    5- كود عند الضغط على q +e يتم تصوير السيارة من الامام ( يتم توجيه الكامرة نحو السيارة من الامام مع امكانية التحرك)
    6- كود عندما تنقلب السيارة يتم تعديلها والاستمرار
    7- كود يجعل اليسارة تتحرك بسرعة جنونية

    الرجاء من الاخوة ان يساعدوني ولو بكود واحد
    ملاحظة:- اريد جميع الاكواد بلغة JavaScript

    دع الأيام تفعــــــــل ما تشــاء ................................ وطب نفسا إذا حكم القضاء
    ولا تجــــــــزع لحادثة الليالي ............................... فما لحـــوادث الدنيا بقـــــاء
    وكن رجلا على الأهوال جلدا ................................. وشيمتك السماحة والوفـــاء
    وإن كثرت عيوبك في البرايا .................................. وسرك أن يكون لها غطـاء


  • #2
    هذا كود محرك السيارة كامل

    private var wheelRadius : float = 0.4;
    var suspensionRange : float = 0.1;
    var suspensionDamper : float = 50;
    var suspensionSpringFront : float = 18500;
    var suspensionSpringRear : float = 9000;

    public var brakeLights : Material;

    var dragMultiplier : Vector3 = new Vector3(2, 5, 1);

    var throttle : float = 0;
    private var steer : float = 0;
    private var handbrake : boolean = false;

    var centerOfMass : Transform;

    var frontWheels : Transform[];
    var rearWheels : Transform[];

    private var wheels : Wheel[];
    wheels = new Wheel[frontWheels.Length + rearWheels.Length];

    private var wfc : WheelFrictionCurve;

    var topSpeed : float = 160;
    var numberOfGears : int = 5;

    var maximumTurn : int = 15;
    var minimumTurn : int = 10;

    var resetTime : float = 5.0;
    private var resetTimer : float = 0.0;

    private var engineForceValues : float[];
    private var gearSpeeds : float[];

    private var currentGear : int;
    private var currentEnginePower : float = 0.0;

    private var handbrakeXDragFactor : float = 0.5;
    private var initialDragMultiplierX : float = 10.0;
    private var handbrakeTime : float = 0.0;
    private var handbrakeTimer : float = 1.0;

    private var skidmarks : Skidmarks = null;
    private var skidSmoke : ParticleEmitter = null;
    var skidmarkTime : float[];

    private var sound : SoundController = null;
    sound = transform.GetComponent(SoundController);

    private var canSteer : boolean;
    private var canDrive : boolean;

    class Wheel
    {
    var collider : WheelCollider;
    var wheelGraphic : Transform;
    var tireGraphic : Transform;
    var driveWheel : boolean = false;
    var steerWheel : boolean = false;
    var lastSkidmark : int = -1;
    var lastEmitPosition : Vector3 = Vector3.zero;
    var lastEmitTime : float = Time.time;
    var wheelVelo : Vector3 = Vector3.zero;
    var groundSpeed : Vector3 = Vector3.zero;
    }

    function Start()
    {
    // Measuring 1 - 60
    accelerationTimer = Time.time;

    SetupWheelColliders();

    SetupCenterOfMass();

    topSpeed = Convert_Miles_Per_Hour_To_Meters_Per_Second(topSpeed);

    SetupGears();

    SetUpSkidmarks();

    initialDragMultiplierX = dragMultiplier.x;
    }

    function Update()
    {
    var relativeVelocity : Vector3 = transform.InverseTransformDirection(rigidbody.velocity);

    GetInput();

    Check_If_Car_Is_Flipped();

    UpdateWheelGraphics(relativeVelocity);

    UpdateGear(relativeVelocity);
    }

    function FixedUpdate()
    {
    // The rigidbody velocity is always given in world space, but in order to work in local space of the car model we need to transform it first.
    var relativeVelocity : Vector3 = transform.InverseTransformDirection(rigidbody.velocity);

    CalculateState();

    UpdateFriction(relativeVelocity);

    UpdateDrag(relativeVelocity);

    CalculateEnginePower(relativeVelocity);

    ApplyThrottle(canDrive, relativeVelocity);

    ApplySteering(canSteer, relativeVelocity);
    }

    /**************************************************/
    /* Functions called from Start() */
    /**************************************************/

    function SetupWheelColliders()
    {
    SetupWheelFrictionCurve();

    var wheelCount : int = 0;

    for (var t : Transform in frontWheels)
    {
    wheels[wheelCount] = SetupWheel(t, true);
    wheelCount++;
    }

    for (var t : Transform in rearWheels)
    {
    wheels[wheelCount] = SetupWheel(t, false);
    wheelCount++;
    }
    }

    function SetupWheelFrictionCurve()
    {
    wfc = new WheelFrictionCurve();
    wfc.extremumSlip = 1;
    wfc.extremumValue = 50;
    wfc.asymptoteSlip = 2;
    wfc.asymptoteValue = 25;
    wfc.stiffness = 1;
    }

    function SetupWheel(wheelTransform : Transform, isFrontWheel : boolean)
    {
    var go : GameObject = new GameObject(wheelTransform.name + " Collider");
    go.transform.position = wheelTransform.position;
    go.transform.parent = transform;
    go.transform.rotation = wheelTransform.rotation;

    var wc : WheelCollider = go.AddComponent(typeof(WheelCollider)) as WheelCollider;
    wc.suspensionDistance = suspensionRange;
    var js : JointSpring = wc.suspensionSpring;

    if (isFrontWheel)
    js.spring = suspensionSpringFront;
    else
    js.spring = suspensionSpringRear;

    js.damper = suspensionDamper;
    wc.suspensionSpring = js;

    wheel = new Wheel();
    wheel.collider = wc;
    wc.sidewaysFriction = wfc;
    wheel.wheelGraphic = wheelTransform;
    wheel.tireGraphic = wheelTransform.GetComponentsInChildren(Transform)[1];

    wheelRadius = wheel.tireGraphic.renderer.bounds.size.y / 2;
    wheel.collider.radius = wheelRadius;

    if (isFrontWheel)
    {
    wheel.steerWheel = true;

    go = new GameObject(wheelTransform.name + " Steer Column");
    go.transform.position = wheelTransform.position;
    go.transform.rotation = wheelTransform.rotation;
    go.transform.parent = transform;
    wheelTransform.parent = go.transform;
    }
    else
    wheel.driveWheel = true;

    return wheel;
    }

    function SetupCenterOfMass()
    {
    if(centerOfMass != null)
    rigidbody.centerOfMass = centerOfMass.localPosition;
    }

    function SetupGears()
    {
    engineForceValues = new float[numberOfGears];
    gearSpeeds = new float[numberOfGears];

    var tempTopSpeed : float = topSpeed;

    for(var i = 0; i < numberOfGears; i++)
    {
    if(i > 0)
    gearSpeeds[i] = tempTopSpeed / 4 + gearSpeeds[i-1];
    else
    gearSpeeds[i] = tempTopSpeed / 4;

    tempTopSpeed -= tempTopSpeed / 4;
    }

    var engineFactor : float = topSpeed / gearSpeeds[gearSpeeds.Length - 1];

    for(i = 0; i < numberOfGears; i++)
    {
    var maxLinearDrag : float = gearSpeeds[i] * gearSpeeds[i];// * dragMultiplier.z;
    engineForceValues[i] = maxLinearDrag * engineFactor;
    }
    }

    function SetUpSkidmarks()
    {
    if(FindObjectOfType(Skidmarks))
    {
    skidmarks = FindObjectOfType(Skidmarks);
    skidSmoke = skidmarks.GetComponentInChildren(ParticleEmitter);
    }
    else
    Debug.Log("No skidmarks object found. Skidmarks will not be drawn");

    skidmarkTime = new float[4];
    for (var f : float in skidmarkTime)
    f = 0.0;
    }

    /**************************************************/
    /* Functions called from Update() */
    /**************************************************/

    function GetInput()
    {
    throttle = Input.GetAxis("Vertical");
    steer = Input.GetAxis("Horizontal");

    if(throttle < 0.0)
    brakeLights.SetFloat("_Intensity", Mathf.Abs(throttle));
    else
    brakeLights.SetFloat("_Intensity", 0.0);

    CheckHandbrake();
    }

    function CheckHandbrake()
    {
    if(Input.GetKey("space"))
    {
    if(!handbrake)
    {
    handbrake = true;
    handbrakeTime = Time.time;
    dragMultiplier.x = initialDragMultiplierX * handbrakeXDragFactor;
    }
    }
    else if(handbrake)
    {
    handbrake = false;
    StartCoroutine(StopHandbraking(Mathf.Min(5, Time.time - handbrakeTime)));
    }
    }

    function StopHandbraking(seconds : float)
    {
    var diff : float = initialDragMultiplierX - dragMultiplier.x;
    handbrakeTimer = 1;

    // Get the x value of the dragMultiplier back to its initial value in the specified time.
    while(dragMultiplier.x < initialDragMultiplierX && !handbrake)
    {
    dragMultiplier.x += diff * (Time.deltaTime / seconds);
    handbrakeTimer -= Time.deltaTime / seconds;
    yield;
    }

    dragMultiplier.x = initialDragMultiplierX;
    handbrakeTimer = 0;
    }

    function Check_If_Car_Is_Flipped()
    {
    if(transform.localEulerAngles.z > 80 && transform.localEulerAngles.z < 280)
    resetTimer += Time.deltaTime;
    else
    resetTimer = 0;

    if(resetTimer > resetTime)
    FlipCar();
    }

    function FlipCar()
    {
    transform.rotation = Quaternion.LookRotation(transform.forward);
    transform.position += Vector3.up * 0.5;
    rigidbody.velocity = Vector3.zero;
    rigidbody.angularVelocity = Vector3.zero;
    resetTimer = 0;
    currentEnginePower = 0;
    }

    var wheelCount : float;
    function UpdateWheelGraphics(relativeVelocity : Vector3)
    {
    wheelCount = -1;

    for(var w : Wheel in wheels)
    {
    wheelCount++;
    var wheel : WheelCollider = w.collider;
    var wh : WheelHit = new WheelHit();

    // First we get the velocity at the point where the wheel meets the ground, if the wheel is touching the ground
    if(wheel.GetGroundHit(wh))
    {
    w.wheelGraphic.localPosition = wheel.transform.up * (wheelRadius + wheel.transform.InverseTransformPoint(wh.point).y);
    w.wheelVelo = rigidbody.GetPointVelocity(wh.point);
    w.groundSpeed = w.wheelGraphic.InverseTransformDirection(w.wheelVelo);

    // Code to handle skidmark drawing. Not covered in the tutorial
    if(skidmarks)
    {
    if(skidmarkTime[wheelCount] < 0.02 && w.lastSkidmark != -1)
    {
    skidmarkTime[wheelCount] += Time.deltaTime;
    }
    else
    {
    var dt : float = skidmarkTime[wheelCount] == 0.0 ? Time.deltaTime : skidmarkTime[wheelCount];
    skidmarkTime[wheelCount] = 0.0;

    var handbrakeSkidding : float = handbrake && w.driveWheel ? w.wheelVelo.magnitude * 0.3 : 0;
    var skidGroundSpeed = Mathf.Abs(w.groundSpeed.x) - 15;
    if(skidGroundSpeed > 0 || handbrakeSkidding > 0)
    {
    var staticVel : Vector3 = transform.TransformDirection(skidSmoke.localVelocity) + skidSmoke.worldVelocity;
    if(w.lastSkidmark != -1)
    {
    var emission : float = UnityEngine.Random.Range(skidSmoke.minEmission, skidSmoke.maxEmission);
    var lastParticleCount : float = w.lastEmitTime * emission;
    var currentParticleCount : float = Time.time * emission;
    var noOfParticles : int = Mathf.CeilToInt(currentParticleCount) - Mathf.CeilToInt(lastParticleCount);
    var lastParticle : int = Mathf.CeilToInt(lastParticleCount);

    for(var i = 0; i <= noOfParticles; i++)
    {
    var particleTime : float = Mathf.InverseLerp(lastParticleCount, currentParticleCount, lastParticle + i);
    skidSmoke.Emit( Vector3.Lerp(w.lastEmitPosition, wh.point, particleTime) + new Vector3(Random.Range(-0.1, 0.1), Random.Range(-0.1, 0.1), Random.Range(-0.1, 0.1)), staticVel + (w.wheelVelo * 0.05), Random.Range(skidSmoke.minSize, skidSmoke.maxSize) * Mathf.Clamp(skidGroundSpeed * 0.1,0.5,1), Random.Range(skidSmoke.minEnergy, skidSmoke.maxEnergy), Color.white);
    }
    }
    else
    {
    skidSmoke.Emit( wh.point + new Vector3(Random.Range(-0.1, 0.1), Random.Range(-0.1, 0.1), Random.Range(-0.1, 0.1)), staticVel + (w.wheelVelo * 0.05), Random.Range(skidSmoke.minSize, skidSmoke.maxSize) * Mathf.Clamp(skidGroundSpeed * 0.1,0.5,1), Random.Range(skidSmoke.minEnergy, skidSmoke.maxEnergy), Color.white);
    }

    w.lastEmitPosition = wh.point;
    w.lastEmitTime = Time.time;

    w.lastSkidmark = skidmarks.AddSkidMark(wh.point + rigidbody.velocity * dt, wh.normal, (skidGroundSpeed * 0.1 + handbrakeSkidding) * Mathf.Clamp01(wh.force / wheel.suspensionSpring.spring), w.lastSkidmark);
    sound.Skid(true, Mathf.Clamp01(skidGroundSpeed * 0.1));
    }
    else
    {
    w.lastSkidmark = -1;
    sound.Skid(false, 0);
    }
    }
    }
    }
    else
    {
    // If the wheel is not touching the ground we set the position of the wheel graphics to
    // the wheel's transform position + the range of the suspension.
    w.wheelGraphic.position = wheel.transform.position + (-wheel.transform.up * suspensionRange);
    if(w.steerWheel)
    w.wheelVelo *= 0.9;
    else
    w.wheelVelo *= 0.9 * (1 - throttle);

    if(skidmarks)
    {
    w.lastSkidmark = -1;
    sound.Skid(false, 0);
    }
    }
    // If the wheel is a steer wheel we apply two rotations:
    // *Rotation around the Steer Column (visualizes the steer direction)
    // *Rotation that visualizes the speed
    if(w.steerWheel)
    {
    var ea : Vector3 = w.wheelGraphic.parent.localEulerAngles;
    ea.y = steer * maximumTurn;
    w.wheelGraphic.parent.localEulerAngles = ea;
    w.tireGraphic.Rotate(Vector3.right * (w.groundSpeed.z / wheelRadius) * Time.deltaTime * Mathf.Rad2Deg);
    }
    else if(!handbrake && w.driveWheel)
    {
    // If the wheel is a drive wheel it only gets the rotation that visualizes speed.
    // If we are hand braking we don't rotate it.
    w.tireGraphic.Rotate(Vector3.right * (w.groundSpeed.z / wheelRadius) * Time.deltaTime * Mathf.Rad2Deg);
    }
    }
    }

    function UpdateGear(relativeVelocity : Vector3)
    {
    currentGear = 0;
    for(var i = 0; i < numberOfGears - 1; i++)
    {
    if(relativeVelocity.z > gearSpeeds[i])
    currentGear = i + 1;
    }
    }

    /**************************************************/
    /* Functions called from FixedUpdate() */
    /**************************************************/

    function UpdateDrag(relativeVelocity : Vector3)
    {
    var relativeDrag : Vector3 = new Vector3( -relativeVelocity.x * Mathf.Abs(relativeVelocity.x),
    -relativeVelocity.y * Mathf.Abs(relativeVelocity.y),
    -relativeVelocity.z * Mathf.Abs(relativeVelocity.z) );

    var drag = Vector3.Scale(dragMultiplier, relativeDrag);

    if(initialDragMultiplierX > dragMultiplier.x) // Handbrake code
    {
    drag.x /= (relativeVelocity.magnitude / (topSpeed / ( 1 + 2 * handbrakeXDragFactor ) ) );
    drag.z *= (1 + Mathf.Abs(Vector3.Dot(rigidbody.velocity.normalized, transform.forward)));
    drag += rigidbody.velocity * Mathf.Clamp01(rigidbody.velocity.magnitude / topSpeed);
    }
    else // No handbrake
    {
    drag.x *= topSpeed / relativeVelocity.magnitude;
    }

    if(Mathf.Abs(relativeVelocity.x) < 5 && !handbrake)
    drag.x = -relativeVelocity.x * dragMultiplier.x;


    rigidbody.AddForce(transform.TransformDirection(drag) * rigidbody.mass * Time.deltaTime);
    }

    function UpdateFriction(relativeVelocity : Vector3)
    {
    var sqrVel : float = relativeVelocity.x * relativeVelocity.x;

    // Add extra sideways friction based on the car's turning velocity to avoid slipping
    wfc.extremumValue = Mathf.Clamp(300 - sqrVel, 0, 300);
    wfc.asymptoteValue = Mathf.Clamp(150 - (sqrVel / 2), 0, 150);

    for(var w : Wheel in wheels)
    {
    w.collider.sidewaysFriction = wfc;
    w.collider.forwardFriction = wfc;
    }
    }

    function CalculateEnginePower(relativeVelocity : Vector3)
    {
    if(throttle == 0)
    {
    currentEnginePower -= Time.deltaTime * 200;
    }
    else if( HaveTheSameSign(relativeVelocity.z, throttle) )
    {
    normPower = (currentEnginePower / engineForceValues[engineForceValues.Length - 1]) * 2;
    currentEnginePower += Time.deltaTime * 200 * EvaluateNormPower(normPower);
    }
    else
    {
    currentEnginePower -= Time.deltaTime * 300;
    }

    if(currentGear == 0)
    currentEnginePower = Mathf.Clamp(currentEnginePower, 0, engineForceValues[0]);
    else
    currentEnginePower = Mathf.Clamp(currentEnginePower, engineForceValues[currentGear - 1], engineForceValues[currentGear]);
    }

    function CalculateState()
    {
    canDrive = false;
    canSteer = false;

    for(var w : Wheel in wheels)
    {
    if(w.collider.isGrounded)
    {
    if(w.steerWheel)
    canSteer = true;
    if(w.driveWheel)
    canDrive = true;
    }
    }
    }

    function ApplyThrottle(canDrive : boolean, relativeVelocity : Vector3)
    {
    if(canDrive)
    {
    var throttleForce : float = 0;
    var brakeForce : float = 0;

    if (HaveTheSameSign(relativeVelocity.z, throttle))
    {
    if (!handbrake)
    throttleForce = Mathf.Sign(throttle) * currentEnginePower * rigidbody.mass;
    }
    else
    brakeForce = Mathf.Sign(throttle) * engineForceValues[0] * rigidbody.mass;

    rigidbody.AddForce(transform.forward * Time.deltaTime * (throttleForce + brakeForce));
    }
    }

    function ApplySteering(canSteer : boolean, relativeVelocity : Vector3)
    {
    if(canSteer)
    {
    var turnRadius : float = 3.0 / Mathf.Sin((90 - (steer * 30)) * Mathf.Deg2Rad);
    var minMaxTurn : float = EvaluateSpeedToTurn(rigidbody.velocity.magnitude);
    var turnSpeed : float = Mathf.Clamp(relativeVelocity.z / turnRadius, -minMaxTurn / 10, minMaxTurn / 10);

    transform.RotateAround( transform.position + transform.right * turnRadius * steer,
    transform.up,
    turnSpeed * Mathf.Rad2Deg * Time.deltaTime * steer);

    var debugStartPoint = transform.position + transform.right * turnRadius * steer;
    var debugEndPoint = debugStartPoint + Vector3.up * 5;

    Debug.DrawLine(debugStartPoint, debugEndPoint, Color.red);

    if(initialDragMultiplierX > dragMultiplier.x) // Handbrake
    {
    var rotationDirection : float = Mathf.Sign(steer); // rotationDirection is -1 or 1 by default, depending on steering
    if(steer == 0)
    {
    if(rigidbody.angularVelocity.y < 1) // If we are not steering and we are handbraking and not rotating fast, we apply a random rotationDirection
    rotationDirection = Random.Range(-1.0, 1.0);
    else
    rotationDirection = rigidbody.angularVelocity.y; // If we are rotating fast we are applying that rotation to the car
    }
    // -- Finally we apply this rotation around a point between the cars front wheels.
    transform.RotateAround( transform.TransformPoint( ( frontWheels[0].localPosition + frontWheels[1].localPosition) * 0.5),
    transform.up,
    rigidbody.velocity.magnitude * Mathf.Clamp01(1 - rigidbody.velocity.magnitude / topSpeed) * rotationDirection * Time.deltaTime * 2);
    }
    }
    }

    /**************************************************/
    /* Utility Functions */
    /**************************************************/

    function Convert_Miles_Per_Hour_To_Meters_Per_Second(value : float) : float
    {
    return value * 0.44704;
    }

    function Convert_Meters_Per_Second_To_Miles_Per_Hour(value : float) : float
    {
    return value * 2.23693629;
    }

    function HaveTheSameSign(first : float, second : float) : boolean
    {
    if (Mathf.Sign(first) == Mathf.Sign(second))
    return true;
    else
    return false;
    }

    function EvaluateSpeedToTurn(speed : float)
    {
    if(speed > topSpeed / 2)
    return minimumTurn;

    var speedIndex : float = 1 - (speed / (topSpeed / 2));
    return minimumTurn + speedIndex * (maximumTurn - minimumTurn);
    }

    function EvaluateNormPower(normPower : float)
    {
    if(normPower < 1)
    return 10 - normPower * 9;
    else
    return 1.9 - normPower * 0.9;
    }

    function GetGearState()
    {
    var relativeVelocity : Vector3 = transform.InverseTransformDirection(rigidbody.velocity);
    var lowLimit : float = (currentGear == 0 ? 0 : gearSpeeds[currentGear-1]);
    return (relativeVelocity.z - lowLimit) / (gearSpeeds[currentGear - lowLimit]) * (1 - currentGear * 0.1) + currentGear * 0.1;
    }
    سبحان الله
    الحمد لله
    لا اله الا الله
    الله اكبر
    ..............
    My FaceBook Profile
    Director Jehad Suliman
    My YouTube Channel
    Almahouss.com
    EnAlmahouss.com
    AlGEEK Channel
    ................................
    شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
    على اليوتيوب

    ...................................
    لن تركع امة قائدها محمد
    جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


    تعليق


    • #3
      اخذته من CarTutorial الي موجود في موقع يونيتي هو مشروع تعليمي مجاني
      سبحان الله
      الحمد لله
      لا اله الا الله
      الله اكبر
      ..............
      My FaceBook Profile
      Director Jehad Suliman
      My YouTube Channel
      Almahouss.com
      EnAlmahouss.com
      AlGEEK Channel
      ................................
      شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
      على اليوتيوب

      ...................................
      لن تركع امة قائدها محمد
      جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


      تعليق


      • #4
        مشكور اخوان

        دع الأيام تفعــــــــل ما تشــاء ................................ وطب نفسا إذا حكم القضاء
        ولا تجــــــــزع لحادثة الليالي ............................... فما لحـــوادث الدنيا بقـــــاء
        وكن رجلا على الأهوال جلدا ................................. وشيمتك السماحة والوفـــاء
        وإن كثرت عيوبك في البرايا .................................. وسرك أن يكون لها غطـاء

        تعليق


        • #5
          بدك كمان اكواد انا جاهز
          سبحان الله
          الحمد لله
          لا اله الا الله
          الله اكبر
          ..............
          My FaceBook Profile
          Director Jehad Suliman
          My YouTube Channel
          Almahouss.com
          EnAlmahouss.com
          AlGEEK Channel
          ................................
          شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
          على اليوتيوب

          ...................................
          لن تركع امة قائدها محمد
          جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


          تعليق


          • #6
            هذا كود اثار البريك على الشارع او على الطريق وانت محتاج تنزل الكتاب التعليمي علشان تعرف كيف تفعله

            /////////
            // Skidmarks.js
            //
            // This script controlles the skidmarks for the car. It registers the position, normal etc. of all the small sections of
            // the skidmarks that combined makes up the entire skidmark mesh.
            // A new mesh is auto generated whenever the skidmarks change.
            @script RequireComponent(MeshFilter)
            @script RequireComponent(MeshRenderer)

            var maxMarks : int = 1024; // Maximum number of marks total handled by one instance of the script.
            var markWidth : float = 0.275; // The width of the skidmarks. Should match the width of the wheel that it is used for. In meters.
            var groundOffset : float = 0.02; // The distance the skidmarks is places above the surface it is placed upon. In meters.
            var minDistance : float = 0.1; // The minimum distance between two marks places next to each other.

            private var indexShift : int;
            private var numMarks : int = 0;

            // Variables for each mark created. Needed to generate the correct mesh.
            class markSection{
            public var pos : Vector3 = Vector3.zero;
            public var normal : Vector3 = Vector3.zero;
            public var tangent : Vector4 = Vector4.zero;
            public var posl : Vector3 = Vector3.zero;
            public var posr: Vector3 = Vector3.zero;
            public var intensity : float = 0.0;
            public var lastIndex : int = 0;
            };

            private var skidmarks : markSection[];

            private var updated : boolean = false;

            // Initiallizes the array holding the skidmark sections.
            function Awake()
            {
            skidmarks = new markSection[maxMarks];
            for(var i = 0; i < maxMarks; i++)
            skidmarks[i]=new markSection();
            if(GetComponent(MeshFilter).mesh == null)
            GetComponent(MeshFilter).mesh = new Mesh();
            }

            // Function called by the wheels that is skidding. Gathers all the information needed to
            // create the mesh later. Sets the intensity of the skidmark section b setting the alpha
            // of the vertex color.
            function AddSkidMark(pos : Vector3, normal : Vector3, intensity : float, lastIndex : int)
            {
            if(intensity > 1)
            intensity = 1.0;
            if(intensity < 0)
            return -1;
            var curr : markSection = skidmarks[numMarks % maxMarks];
            curr.pos = pos + normal * groundOffset;
            curr.normal = normal;
            curr.intensity = intensity;
            curr.lastIndex = lastIndex;

            if(lastIndex != -1)
            {
            var last : markSection = skidmarks[lastIndex % maxMarks];
            var dir : Vector3 = (curr.pos - last.pos);
            var xDir : Vector3 = Vector3.Cross(dir,normal).normalized;

            curr.posl = curr.pos + xDir * markWidth * 0.5;
            curr.posr = curr.pos - xDir * markWidth * 0.5;
            curr.tangent = new Vector4(xDir.x, xDir.y, xDir.z, 1);

            if(last.lastIndex == -1)
            {
            last.tangent = curr.tangent;
            last.posl = curr.pos + xDir * markWidth * 0.5;
            last.posr = curr.pos - xDir * markWidth * 0.5;
            }
            }
            numMarks++;
            updated = true;
            return numMarks -1;
            }

            // If the mesh needs to be updated, i.e. a new section has been added,
            // the current mesh is removed, and a new mesh for the skidmarks is generated.
            function LateUpdate()
            {
            if(!updated)
            {
            return;
            }
            updated = false;

            var mesh : Mesh = GetComponent(MeshFilter).mesh;
            mesh.Clear();
            var segmentCount : int = 0;
            for(var j : int = 0; j < numMarks && j < maxMarks; j++)
            if(skidmarks[j].lastIndex != -1 && skidmarks[j].lastIndex > numMarks - maxMarks)
            segmentCount++;

            var vertices : Vector3[] = new Vector3[segmentCount * 4];
            var normals : Vector3[] = new Vector3[segmentCount * 4];
            var tangents : Vector4[] = new Vector4[segmentCount * 4];
            var colors : Color[] = new Color[segmentCount * 4];
            var uvs : Vector2[] = new Vector2[segmentCount * 4];
            var triangles : int[] = new int[segmentCount * 6];
            segmentCount = 0;
            for(var i : int = 0; i < numMarks && i < maxMarks; i++)
            if(skidmarks[i].lastIndex != -1 && skidmarks[i].lastIndex > numMarks - maxMarks)
            {
            var curr : markSection = skidmarks[i];
            var last : markSection = skidmarks[curr.lastIndex % maxMarks];
            vertices[segmentCount * 4 + 0] = last.posl;
            vertices[segmentCount * 4 + 1] = last.posr;
            vertices[segmentCount * 4 + 2] = curr.posl;
            vertices[segmentCount * 4 + 3] = curr.posr;

            normals[segmentCount * 4 + 0] = last.normal;
            normals[segmentCount * 4 + 1] = last.normal;
            normals[segmentCount * 4 + 2] = curr.normal;
            normals[segmentCount * 4 + 3] = curr.normal;

            tangents[segmentCount * 4 + 0] = last.tangent;
            tangents[segmentCount * 4 + 1] = last.tangent;
            tangents[segmentCount * 4 + 2] = curr.tangent;
            tangents[segmentCount * 4 + 3] = curr.tangent;

            colors[segmentCount * 4 + 0]=new Color(0, 0, 0, last.intensity);
            colors[segmentCount * 4 + 1]=new Color(0, 0, 0, last.intensity);
            colors[segmentCount * 4 + 2]=new Color(0, 0, 0, curr.intensity);
            colors[segmentCount * 4 + 3]=new Color(0, 0, 0, curr.intensity);

            uvs[segmentCount * 4 + 0] = new Vector2(0, 0);
            uvs[segmentCount * 4 + 1] = new Vector2(1, 0);
            uvs[segmentCount * 4 + 2] = new Vector2(0, 1);
            uvs[segmentCount * 4 + 3] = new Vector2(1, 1);

            triangles[segmentCount * 6 + 0] = segmentCount * 4 + 0;
            triangles[segmentCount * 6 + 2] = segmentCount * 4 + 1;
            triangles[segmentCount * 6 + 1] = segmentCount * 4 + 2;

            triangles[segmentCount * 6 + 3] = segmentCount * 4 + 2;
            triangles[segmentCount * 6 + 5] = segmentCount * 4 + 1;
            triangles[segmentCount * 6 + 4] = segmentCount * 4 + 3;
            segmentCount++;
            }
            mesh.vertices=vertices;
            mesh.normals=normals;
            mesh.tangents=tangents;
            mesh.triangles=triangles;
            mesh.colors=colors;
            mesh.uv=uvs;
            }
            سبحان الله
            الحمد لله
            لا اله الا الله
            الله اكبر
            ..............
            My FaceBook Profile
            Director Jehad Suliman
            My YouTube Channel
            Almahouss.com
            EnAlmahouss.com
            AlGEEK Channel
            ................................
            شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
            على اليوتيوب

            ...................................
            لن تركع امة قائدها محمد
            جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


            تعليق


            • #7
              وهذا كود اصوات السيارة من محرك وعجال وبريك ....الخ

              /////////
              // SoundController.js
              //
              // This script controls the sound for a car. It automatically creates the needed AudioSources, and ensures
              // that only a certain number of sound are played at any time, by limiting the number of OneShot
              // audio clip that can be played at any time. This is to ensure that it does not play more sounds than Unity
              // can handle.
              // The script handles the sound for the engine, both idle and running, gearshifts, skidding and crashing.
              // PlayOneShot is used for the non-looping sounds are needed. A separate AudioSource is create for the OneShot
              // AudioClips, since the should not be affected by the pitch-changes applied to other AudioSources.

              private var car : Car;

              var D : AudioClip = null;
              var DVolume : float = 1.0;
              var E : AudioClip = null;
              var EVolume : float = 1.0;
              var F : AudioClip = null;
              var FVolume : float = 1.0;
              var K : AudioClip = null;
              var KVolume : float = 1.0;
              var L : AudioClip = null;
              var LVolume : float = 1.0;

              var wind : AudioClip = null;
              var windVolume : float = 1.0;
              var tunnelSound : AudioClip = null;
              var tunnelVolume : float = 1.0;

              var crashLowSpeedSound : AudioClip = null;
              var crashLowVolume : float = 1.0;
              var crashHighSpeedSound : AudioClip = null;
              var crashHighVolume : float = 1.0;
              var skidSound : AudioClip = null;

              var BackgroundMusic : AudioClip = null;
              var BackgroundMusicVolume : float = 0.6;

              private var DAudio : AudioSource = null;
              private var EAudio : AudioSource = null;
              private var FAudio : AudioSource = null;
              private var KAudio : AudioSource = null;
              private var LAudio : AudioSource = null;

              private var tunnelAudio : AudioSource = null;
              private var windAudio : AudioSource = null;
              private var skidAudio : AudioSource = null;
              private var carAudio : AudioSource = null;

              private var backgroundMusic : AudioSource = null;

              private var carMaxSpeed : float = 55.0;
              private var gearShiftTime : float = 0.1;
              private var shiftingGear : boolean = false;
              private var gearShiftsStarted : int = 0;
              private var crashesStarted : int = 0;
              private var crashTime : float = 0.2;
              private var oneShotLimit : int = 8;

              private var idleFadeStartSpeed : float = 3.0;
              private var idleFadeStopSpeed : float = 10.0;
              private var idleFadeSpeedDiff : float = 7.0;
              private var speedFadeStartSpeed : float = 0.0;
              private var speedFadeStopSpeed : float = 8.0;
              private var speedFadeSpeedDiff : float = 8.0;

              private var soundsSet : boolean = false;

              private var inputFactor : float = 0;
              private var gear : int = 0;
              private var topGear : int = 6;

              private var idlePitch : float = 0.7;
              private var startPitch : float = 0.85;
              private var lowPitch : float = 1.17;
              private var medPitch : float = 1.25;
              private var highPitchFirst : float = 1.65;
              private var highPitchSecond : float = 1.76;
              private var highPitchThird : float = 1.80;
              private var highPitchFourth : float = 1.86;
              private var shiftPitch : float = 1.44;

              private var prevPitchFactor : float = 0;

              // Create the needed AudioSources
              function Awake()
              {
              car = transform.GetComponent(Car);

              DVolume *= 0.4;
              EVolume *= 0.4;
              FVolume *= 0.4;
              KVolume *= 0.7;
              LVolume *= 0.4;
              windVolume *= 0.4;

              DAudio = gameObject.AddComponent(AudioSource);
              DAudio.loop = true;
              DAudio.clip = D;
              DAudio.volume = DVolume;
              DAudio.Play();

              EAudio = gameObject.AddComponent(AudioSource);
              EAudio.loop = true;
              EAudio.clip = E;
              EAudio.volume = EVolume;
              EAudio.Play();

              FAudio = gameObject.AddComponent(AudioSource);
              FAudio.loop = true;
              FAudio.clip = F;
              FAudio.volume = FVolume;
              FAudio.Play();

              KAudio = gameObject.AddComponent(AudioSource);
              KAudio.loop = true;
              KAudio.clip = K;
              KAudio.volume = KVolume;
              KAudio.Play();

              LAudio = gameObject.AddComponent(AudioSource);
              LAudio.loop = true;
              LAudio.clip = L;
              LAudio.volume = LVolume;
              LAudio.Play();

              windAudio = gameObject.AddComponent(AudioSource);
              windAudio.loop = true;
              windAudio.clip = wind;
              windAudio.volume = windVolume;
              windAudio.Play();

              tunnelAudio = gameObject.AddComponent(AudioSource);
              tunnelAudio.loop = true;
              tunnelAudio.clip = tunnelSound;
              // tunnelAudio.maxVolume = tunnelVolume;
              tunnelAudio.volume = tunnelVolume;

              skidAudio = gameObject.AddComponent(AudioSource);
              skidAudio.loop = true;
              skidAudio.clip = skidSound;
              skidAudio.volume = 0.0;
              skidAudio.Play();

              carAudio = gameObject.AddComponent(AudioSource);
              carAudio.loop = false;
              carAudio.playOnAwake = false;
              carAudio.Stop();

              crashTime = Mathf.Max(crashLowSpeedSound.length, crashHighSpeedSound.length);
              soundsSet = false;

              idleFadeSpeedDiff = idleFadeStopSpeed - idleFadeStartSpeed;
              speedFadeSpeedDiff = speedFadeStopSpeed - speedFadeStartSpeed;

              backgroundMusic = gameObject.AddComponent(AudioSource);
              backgroundMusic.loop = true;
              backgroundMusic.clip = BackgroundMusic;
              // backgroundMusic.maxVolume = BackgroundMusicVolume;
              // backgroundMusic.minVolume = BackgroundMusicVolume;
              backgroundMusic.volume = BackgroundMusicVolume;
              backgroundMusic.Play();
              }

              function Update()
              {
              var carSpeed : float = car.rigidbody.velocity.magnitude;
              var carSpeedFactor : float = Mathf.Clamp01(carSpeed / car.topSpeed);

              KAudio.volume = Mathf.Lerp(0, KVolume, carSpeedFactor);
              windAudio.volume = Mathf.Lerp(0, windVolume, carSpeedFactor * 2);

              if(shiftingGear)
              return;

              var pitchFactor : float = Sinerp(0, topGear, carSpeedFactor);
              var newGear : int = pitchFactor;

              pitchFactor -= newGear;
              var throttleFactor : float = pitchFactor;
              pitchFactor *= 0.3;
              pitchFactor += throttleFactor * (0.7) * Mathf.Clamp01(car.throttle * 2);

              if(newGear != gear)
              {
              if(newGear > gear)
              GearShift(prevPitchFactor, pitchFactor, gear, true);
              else
              GearShift(prevPitchFactor, pitchFactor, gear, false);
              gear = newGear;
              }
              else
              {
              var newPitch : float = 0;
              if(gear == 0)
              newPitch = Mathf.Lerp(idlePitch, highPitchFirst, pitchFactor);
              else
              if(gear == 1)
              newPitch = Mathf.Lerp(startPitch, highPitchSecond, pitchFactor);
              else
              if(gear == 2)
              newPitch = Mathf.Lerp(lowPitch, highPitchThird, pitchFactor);
              else
              newPitch = Mathf.Lerp(medPitch, highPitchFourth, pitchFactor);
              SetPitch(newPitch);
              SetVolume(newPitch);
              }
              prevPitchFactor = pitchFactor;
              }

              function Coserp(start : float, end : float, value : float) : float
              {
              return Mathf.Lerp(start, end, 1.0 - Mathf.Cos(value * Mathf.PI * 0.5));
              }

              function Sinerp(start : float, end : float, value : float) : float
              {
              return Mathf.Lerp(start, end, Mathf.Sin(value * Mathf.PI * 0.5));
              }

              function SetPitch(pitch : float)
              {
              DAudio.pitch = pitch;
              EAudio.pitch = pitch;
              FAudio.pitch = pitch;
              LAudio.pitch = pitch;
              tunnelAudio.pitch = pitch;
              }

              function SetVolume(pitch : float)
              {
              var pitchFactor : float = Mathf.Lerp(0, 1, (pitch - startPitch) / (highPitchSecond - startPitch));
              DAudio.volume = Mathf.Lerp(0, DVolume, pitchFactor);
              var fVolume : float = Mathf.Lerp(FVolume * 0.80, FVolume, pitchFactor);
              FAudio.volume = fVolume * 0.7 + fVolume * 0.3 * Mathf.Clamp01(car.throttle);
              var eVolume : float = Mathf.Lerp(EVolume * 0.89, EVolume, pitchFactor);
              EAudio.volume = eVolume * 0.8 + eVolume * 0.2 * Mathf.Clamp01(car.throttle);
              }

              function GearShift(oldPitchFactor : float, newPitchFactor : float, gear : int, shiftUp : boolean)
              {
              shiftingGear = true;

              var timer : float = 0;
              var pitchFactor : float = 0;
              var newPitch : float = 0;

              if(shiftUp)
              {
              while(timer < gearShiftTime)
              {
              pitchFactor = Mathf.Lerp(oldPitchFactor, 0, timer / gearShiftTime);
              if(gear == 0)
              newPitch = Mathf.Lerp(lowPitch, highPitchFirst, pitchFactor);
              else
              newPitch = Mathf.Lerp(lowPitch, highPitchSecond, pitchFactor);
              SetPitch(newPitch);
              SetVolume(newPitch);
              timer += Time.deltaTime;
              yield;
              }
              }
              else
              {
              while(timer < gearShiftTime)
              {
              pitchFactor = Mathf.Lerp(0, 1, timer / gearShiftTime);
              newPitch = Mathf.Lerp(lowPitch, shiftPitch, pitchFactor);
              SetPitch(newPitch);
              SetVolume(newPitch);
              timer += Time.deltaTime;
              yield;
              }
              }

              shiftingGear = false;
              }

              function Skid(play : boolean, volumeFactor : float)
              {
              if(!skidAudio)
              return;
              if(play)
              {
              skidAudio.volume = Mathf.Clamp01(volumeFactor + 0.3);
              }
              else
              skidAudio.volume = 0.0;
              }

              // Checks if the max amount of crash sounds has been started, and
              // if the max amount of total one shot sounds has been started.
              function Crash(volumeFactor : float)
              {
              if(crashesStarted > 3 || OneShotLimitReached())
              return;
              if(volumeFactor > 0.9)
              carAudio.PlayOneShot(crashHighSpeedSound, Mathf.Clamp01((0.5 + volumeFactor * 0.5) * crashHighVolume));
              carAudio.PlayOneShot(crashLowSpeedSound, Mathf.Clamp01(volumeFactor * crashLowVolume));
              crashesStarted++;

              yield new WaitForSeconds(crashTime);

              crashesStarted--;
              }

              // A function for testing if the maximum amount of OneShot AudioClips
              // has been started.
              function OneShotLimitReached()
              {
              return (crashesStarted + gearShiftsStarted) > oneShotLimit;
              }

              function OnTriggerEnter(coll : Collider)
              {
              var st : SoundToggler = coll.transform.GetComponent(SoundToggler);
              if(st)
              ControlSound(true, st.fadeTime);
              }

              function OnTriggerExit(coll : Collider)
              {
              var st : SoundToggler = coll.transform.GetComponent(SoundToggler);
              if(st)
              ControlSound(false, st.fadeTime);
              }

              function ControlSound(play : boolean, fadeTime : float)
              {
              var timer : float = 0;
              if(play && !tunnelAudio.isPlaying)
              {
              tunnelAudio.volume = 0;
              tunnelAudio.Play();
              while(timer < fadeTime)
              {
              tunnelAudio.volume = Mathf.Lerp(0, tunnelVolume, timer / fadeTime);
              timer += Time.deltaTime;
              yield;
              }
              }
              else if(!play && tunnelAudio.isPlaying)
              {
              while(timer < fadeTime)
              {
              tunnelAudio.volume = Mathf.Lerp(0, tunnelVolume, timer / fadeTime);
              timer += Time.deltaTime;
              yield;
              }
              tunnelAudio.Stop();
              }
              }
              سبحان الله
              الحمد لله
              لا اله الا الله
              الله اكبر
              ..............
              My FaceBook Profile
              Director Jehad Suliman
              My YouTube Channel
              Almahouss.com
              EnAlmahouss.com
              AlGEEK Channel
              ................................
              شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
              على اليوتيوب

              ...................................
              لن تركع امة قائدها محمد
              جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


              تعليق


              • #8
                وهذا كود الاصتدام صراحة ما جربته وما بعرف كيف بشتغل تفضل

                var sound : SoundController;
                sound = transform.root.GetComponent(SoundController);

                private var car : Car;
                car = transform.GetComponent(Car);

                function OnCollisionEnter(collInfo : Collision)
                {
                if(enabled && collInfo.contacts.Length > 0)
                {
                var volumeFactor : float = Mathf.Clamp01(collInfo.relativeVelocity.magnitude * 0.08);
                volumeFactor *= Mathf.Clamp01(0.3 + Mathf.Abs(Vector3.Dot(collInfo.relativeVelocity.normalized, collInfo.contacts[0].normal)));
                volumeFactor = volumeFactor * 0.5 + 0.5;
                sound.Crash(volumeFactor);
                }
                }
                سبحان الله
                الحمد لله
                لا اله الا الله
                الله اكبر
                ..............
                My FaceBook Profile
                Director Jehad Suliman
                My YouTube Channel
                Almahouss.com
                EnAlmahouss.com
                AlGEEK Channel
                ................................
                شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
                على اليوتيوب

                ...................................
                لن تركع امة قائدها محمد
                جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


                تعليق


                • #9
                  وهذا كود كاميرا العاب السيارات

                  using UnityEngine;
                  using System.Collections;

                  public class CarCamera : MonoBehaviour
                  {
                  public Transform target = null;
                  public float height = 1f;
                  public float positionDamping = 3f;
                  public float velocityDamping = 3f;
                  public float distance = 4f;
                  public LayerMask ignoreLayers = -1;

                  private RaycastHit hit = new RaycastHit();

                  private Vector3 prevVelocity = Vector3.zero;
                  private LayerMask raycastLayers = -1;

                  private Vector3 currentVelocity = Vector3.zero;

                  void Start()
                  {
                  raycastLayers = ~ignoreLayers;
                  }

                  void FixedUpdate()
                  {
                  currentVelocity = Vector3.Lerp(prevVelocity, target.root.rigidbody.velocity, velocityDamping * Time.deltaTime);
                  currentVelocity.y = 0;
                  prevVelocity = currentVelocity;
                  }

                  void LateUpdate()
                  {
                  float speedFactor = Mathf.Clamp01(target.root.rigidbody.velocity.magnitude / 70.0f);
                  camera.fieldOfView = Mathf.Lerp(55, 72, speedFactor);
                  float currentDistance = Mathf.Lerp(7.5f, 6.5f, speedFactor);

                  currentVelocity = currentVelocity.normalized;

                  Vector3 newTargetPosition = target.position + Vector3.up * height;
                  Vector3 newPosition = newTargetPosition - (currentVelocity * currentDistance);
                  newPosition.y = newTargetPosition.y;

                  Vector3 targetDirection = newPosition - newTargetPosition;
                  if(Physics.Raycast(newTargetPosition, targetDirection, out hit, currentDistance, raycastLayers))
                  newPosition = hit.point;

                  transform.position = newPosition;
                  transform.LookAt(newTargetPosition);

                  }
                  }
                  سبحان الله
                  الحمد لله
                  لا اله الا الله
                  الله اكبر
                  ..............
                  My FaceBook Profile
                  Director Jehad Suliman
                  My YouTube Channel
                  Almahouss.com
                  EnAlmahouss.com
                  AlGEEK Channel
                  ................................
                  شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
                  على اليوتيوب

                  ...................................
                  لن تركع امة قائدها محمد
                  جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


                  تعليق


                  • #10
                    هذا كل شي متعلق بالسيارات عندي
                    سبحان الله
                    الحمد لله
                    لا اله الا الله
                    الله اكبر
                    ..............
                    My FaceBook Profile
                    Director Jehad Suliman
                    My YouTube Channel
                    Almahouss.com
                    EnAlmahouss.com
                    AlGEEK Channel
                    ................................
                    شاهد الان #كليب_لاجئ للمبدع المتميز عمران البقاعي
                    على اليوتيوب

                    ...................................
                    لن تركع امة قائدها محمد
                    جرب ولا تخف فالذين صنعوا سفية نوح كانوا من الهواة اما المحترفين فهم الذين صنعوا تايتانك - إبراهيم الفقي


                    تعليق


                    • #11
                      لكن هو يتكلم عن لعبة سيارات 2دي

                      تعليق

                      يعمل...
                      X