當前位置:首頁 » 操作系統 » unity3d賽車源碼

unity3d賽車源碼

發布時間: 2022-07-10 11:18:58

1. 有誰用unity3D做過賽車游戲

因為 getkey(w)這些 沒有返回數, 你要是用Input.GetAxis("Horizontal"); 這個其實在按wsad這些按鍵的時候,是返回-1到1的float類型的數的,然後再用這個數去乘以那些東西,就能讓車輪前進了。motorTorque就是用來讓汽車車輪前進的,可以去API裡面查一下WheelCollider裡面有說明。
而rigidbody.velocity 也可以讓有剛體的物體移動,tranform.forward * 1000 則代表你要添加的速度。
你那個 differentialRatio 肯定是跟 Input.GetAxis("Horizontal"); 有關系,你可以在代碼里查找一下。
前面那個 GearRatio 是用來控制汽車的檔數的,速度到一個階段,GearRatio 的數字也會不同,代表了這個檔數。

2. unity3d作業 現急求製作一份賽車類簡單游戲 有酬勞

那你直接用unity5的賽車demo加個場景不就好了嗎

3. unity3d 源碼文件在哪個文件夾

查看源碼的步驟:對著源碼所在的文件夾右鍵,然後選擇Show in Explorer。如圖

4. 求一段unity3D汽車自動駕駛的腳本代碼

1、把腳本直接連到汽車車身網格上,車身要有Rigidbody Component,要有四個輪子網格做子物體。 要想有聲音的話還要有AudioSource Component。

2、打開Inspector,選擇汽車腳本,把四個輪子連接到相對應的Transform參數上。設置wheelRadius參數為你輪子網格的大小。WheelCollider是自動生成的,所以無需手動添加。這樣就能保證運行了,其他的聲音和灰塵可以再添加。

腳本源代碼如下:*/
#pragma strict
//maximal corner and braking acceleration capabilities
var maxCornerAccel=10.0;
var maxBrakeAccel=10.0;
//center of gravity height - effects tilting in corners
var cogY = 0.0;
//engine powerband
var minRPM = 700;
var maxRPM = 6000;
//maximum Engine Torque
var maxTorque = 400;
//automatic transmission shift points
var shiftDownRPM = 2500;
var shiftUpRPM = 5500;
//gear ratios
var gearRatios = [-2.66, 2.66, 1.78, 1.30, 1.00];
var finalDriveRatio = 3.4;
//a basic handling modifier:
//1.0 understeer
//0.0 oversteer
var handlingTendency = 0.7;
//graphical wheel objects
var wheelFR : Transform;
var wheelFL : Transform;
var wheelBR : Transform;
var wheelBL : Transform;
//suspension setup
var suspensionDistance = 0.3;
var springs = 1000;
var dampers = 200;
var wheelRadius = 0.45;
//particle effect for ground st
var groundDustEffect : Transform;
private var queryUserInput = true;
private var engineRPM : float;
private var steerVelo = 0.0;
private var brake = 0.0;
private var handbrake = 0.0;
private var steer = 0.0;
private var motor = 0.0;
//private var skidTime = 0.0;
private var onGround = false;
private var cornerSlip = 0.0;
private var driveSlip = 0.0;
private var wheelRPM : float;
private var gear = 1;
//private var skidmarks : Skidmarks;
private var wheels : WheelData[];
private var wheelY = 0.0;
private var rev = 0.0;
//Functions to be used by external scripts
//controlling the car if required
//===================================================================
//return a status string for the vehicle
function GetStatus(gui : GUIText) {
gui.text="v="+(rigidbody.velocity.magnitude * 3.6).ToString("f1") km/h\ngear= "+gear+"\nrpm= "+engineRPM.ToString("f0");
}
//return an information string for the vehicle
function GetControlString(gui : GUIText) {
gui.text="Use arrow keys to control the jeep,\nspace for handbrake."; }
//Enable or disable user controls
function SetEnableUserInput(enableInput)
{
queryUserInput=enableInput;
}
//Car physics
//===================================================================
//some whee calculation data
class WheelData{ + "
var rotation = 0.0;
var coll : WheelCollider;
var graphic : Transform;
var maxSteerAngle = 0.0;
var lastSkidMark = -1;
var powered = false;
var handbraked = false;
var originalRotation : Quaternion;
};
function Start () {
//setup wheels
wheels=new WheelData[4];
for(i=0;i<4;i++)
wheels[i] = new WheelData();

wheels[0].graphic = wheelFL;
wheels[1].graphic = wheelFR;
wheels[2].graphic = wheelBL;
wheels[3].graphic = wheelBR;
wheels[0].maxSteerAngle=30.0;
wheels[1].maxSteerAngle=30.0;
wheels[2].powered=true;
wheels[3].powered=true;
wheels[2].handbraked=true;
wheels[3].handbraked=true;
for(w in wheels)
{
if(w.graphic==null)
Debug.Log("You need to assign all four wheels for the car script!"); if(!w.graphic.transform.IsChildOf(transform))
Debug.Log("Wheels need to be children of the Object with the car script");
w.originalRotation = w.graphic.localRotation;
//create collider
colliderObject = new GameObject("WheelCollider");
colliderObject.transform.parent = transform;
colliderObject.transform.position = w.graphic.position;
w.coll = colliderObject.AddComponent(WheelCollider);
w.coll.suspensionDistance = suspensionDistance;
w.coll.suspensionSpring.spring = springs;
w.coll.suspensionSpring.damper = dampers;
//no grip, as we simulate handling ourselves
w.coll.forwardFriction.stiffness = 0;
w.coll.sidewaysFriction.stiffness = 0;
w.coll.radius = wheelRadius;
}
//get wheel height (height forces are applied on)
wheelY=wheels[0].graphic.localPosition.y;

//setup center of gravity
rigidbody.centerOfMass.y = cogY;

//find skidmark object
// skidmarks = FindObjectOfType(typeof(Skidmarks));

//shift to first
gear=1;
}
//update wheel status
function UpdateWheels()
{
//calculate handbrake slip for traction gfx
handbrakeSlip=handbrake*rigidbody.velocity.magnitude*0.1;
if(handbrakeSlip>1)
handbrakeSlip=1;

totalSlip=0.0;
onGround=false;
for(w in wheels)
{
//rotate wheel
w.rotation += wheelRPM / 60.0 * -rev * 360.0 * Time.fixedDeltaTime; w.rotation = Mathf.Repeat(w.rotation, 360.0);
w.graphic.localRotation= Quaternion.Euler( w.rotation, w.maxSteerAngle*steer, 0.0 ) * w.originalRotation;
//check if wheel is on ground
if(w.coll.isGrounded)
onGround=true;

slip = cornerSlip+(w.powered?driveSlip:0.0)+(w.handbraked?handbrakeSlip:0.0); totalSlip += slip;

var hit : WheelHit;
var c : WheelCollider;
c = w.coll;
if(c.GetGroundHit(hit))
{
//if the wheel touches the ground, adjust graphical wheel position to reflect springs

w.graphic.localPosition.y-=Vector3.Dot(w.graphic.position-hit.point,transform.up)-w.coll.radius;

//create st on ground if appropiate
if(slip>0.5 && hit.collider.tag=="Dusty")
{
groundDustEffect.position=hit.point;

groundDustEffect.particleEmitter.worldVelocity=rigidbody.velocity*0.5; groundDustEffect.particleEmitter.minEmission=(slip-0.5)*3; groundDustEffect.particleEmitter.maxEmission=(slip-0.5)*3;
groundDustEffect.particleEmitter.Emit(); }

//and skid marks
/*if(slip>0.75 && skidmarks != null)

w.lastSkidMark=skidmarks.AddSkidMark(hit.point,hit.normal,(slip-0.75)*2,w.lastSkidMark);
else
w.lastSkidMark=-1; */
}
// else w.lastSkidMark=-1;
}
totalSlip/=wheels.length;
}
//Automatically shift gears
function AutomaticTransmission()
{
if(gear>0)
{
if(engineRPM>shiftUpRPM&&gear<gearRatios.length-1)
gear++;
if(engineRPM<shiftDownRPM&&gear>1)
gear--;
}
}
//Calculate engine acceleration force for current RPM and trottle
function CalcEngine() : float
{
if(brake+handbrake>0.;motor=0.0;;//ifcarisairborne,justre;if(!onGround);engineRPM+=(motor-0.3)*2;engineRPM=Mathf.Clamp(en;return0.0;;else;AutomaticTransmission();;engineRPM=whee
if(brake+handbrake>0.1)

motor=0.0;

//if car is airborne, just rev engine

if(!onGround)

{

engineRPM += (motor-0.3)*25000.0*Time.deltaTime;

engineRPM = Mathf.Clamp(engineRPM,minRPM,maxRPM);

return 0.0;

}

else

{

AutomaticTransmission();

engineRPM=wheelRPM*gearRatios[gear]*finalDriveRatio;

if(engineRPM<minRPM)

engineRPM=minRPM;

if(engineRPM<maxRPM)

{

//fake a basic torque curve

x = (2*(engineRPM/maxRPM)-1);

torqueCurve = 0.5*(-x*x+2);

torqueToForceRatio = gearRatios[gear]*finalDriveRatio/wheelRadius; return
motor*maxTorque*torqueCurve*torqueToForceRatio;

}

else

//rpm delimiter

return 0.0;

}

}

//Car physics

//The physics of this car are really a trial-and-error based extension of
//basic "Asteriods" physics -- so you will get a pretty arcade-like feel. //This
may or may not be what you want, for a more physical approach research //the
wheel colliders

function HandlePhysics () {

var velo=rigidbody.velocity;

wheelRPM=velo.magnitude*60.0*0.5;

rigidbody.angularVelocity=new

Vector3(rigidbody.angularVelocity.x,0.0,rigidbody.angularVelocity.z);
dir=transform.TransformDirection(Vector3.forward);

flatDir=Vector3.Normalize(new Vector3(dir.x,0,dir.z));

flatVelo=new Vector3(velo.x,0,velo.z);

rev=Mathf.Sign(Vector3.Dot(flatVelo,flatDir));

//when moving backwards or standing and brake is pressed, switch to
reverse

if((rev<0||flatVelo.sqrMagnitude<0.5)&&brake>0.1)

gear=0;

if(gear==0)

{

//when in reverse, flip brake and gas

tmp=brake;

brake=motor;

motor=tmp;

//when moving forward or standing and gas is pressed, switch to drive
if((rev>0||flatVelo.sqrMagnitude<0.5)&&brake>0.1)

gear=1;

}

engineForce=flatDir*CalcEngine();

totalbrake=brake+handbrake*0.5;

if(totalbrake>1.0)totalbrake=1.0;

brakeForce=-flatVelo.normalized*totalbrake*rigidbody.mass*maxBrakeAccel;
flatDir*=flatVelo.magnitude;

flatDir=Quaternion.AngleAxis(steer*30.0,Vector3.up)*flatDir;

flatDir*=rev;

diff=(flatVelo-flatDir).magnitude;

cornerAccel=maxCornerAccel;

if(cornerAccel>diff)cornerAccel=diff;

cornerForce=-(flatVelo-flatDir).normalized*cornerAccel*rigidbody.mass;
cornerSlip=Mathf.Pow(cornerAccel/maxCornerAccel,3);

rigidbody.AddForceAtPosition(brakeForce+engineForce+cornerForce,transform.position+transform.up*wheelY);

handbrakeFactor=1+handbrake*4;

if(rev<0)

handbrakeFactor=1;

veloSteer=((15/(2*velo.magnitude+1))+1)*handbrakeFactor;

steerGrip=(1-handlingTendency*cornerSlip);

if(rev*steer*steerVelo<0)

steerGrip=1;

maxRotSteer=2*Time.fixedDeltaTime*handbrakeFactor*steerGrip;

fVelo=velo.magnitude;

veloFactor=fVelo<1.0?fVelo:Mathf.Pow(velo.magnitude,0.3);

steerVeloInput=rev*steer*veloFactor*0.5*Time.fixedDeltaTime*handbrakeFactor;
if(velo.magnitude<0.1)

steerVeloInput=0;

if(steerVeloInput>steerVelo)

{

steerVelo+=0.02*Time.fixedDeltaTime*veloSteer;

if(steerVeloInput<steerVelo)

steerVelo=steerVeloInput;

}

else

{

steerVelo-=0.02*Time.fixedDeltaTime*veloSteer;

if(steerVeloInput>steerVelo)

steerVelo=steerVeloInput;

}

steerVelo=Mathf.Clamp(steerVelo,-maxRotSteer,maxRotSteer);
transform.Rotate(Vector3.up*steerVelo*57.295788);

}

function FixedUpdate () {

//query input axes if necessarry

if(queryUserInput)

{

brake = Mathf.Clamp01(-Input.GetAxis("Vertical"));

handbrake = Input.GetButton("Jump")?1.0:0.0;

steer = Input.GetAxis("Horizontal");

motor = Mathf.Clamp01(Input.GetAxis("Vertical"));

}

else

{

motor = 0;

steer = 0;

brake = 0;

handbrake = 0;

}

//if car is on ground calculate handling, otherwise just rev the engine
if(onGround)

HandlePhysics();

else

CalcEngine();

//wheel GFX

UpdateWheels();

//engine sounds

audio.pitch=0.5+0.2*motor+0.8*engineRPM/maxRPM;

audio.volume=0.5+0.8*motor+0.2*engineRPM/maxRPM;

}

//Called by DamageReceiver if boat destroyed

function Detonate()

{

//destroy wheels

for( w in wheels )

w.coll.gameObject.active=false; //no more car physics

enabled=false;

}

5. Unity3D這款游戲引擎軟體的源碼是開源的嗎

Unity3D是不開源的。

相關介紹:

Unity類似於Director、Blender game engine、Virtools 或 Torque Game Builder等利用交互的圖型化開發環境為首要方式的軟體。

開放源碼軟體通常是有right的,它的許可證可能包含這樣一些限制: 蓄意的保護它的開放源碼狀態,著者身份的公告,或者開發的控制。「開放源碼」正在被公眾利益軟體組織注冊為認證標記,這也是創立正式的開放源碼定義的一種手段。

(5)unity3d賽車源碼擴展閱讀

開放源碼軟體主要被散布在全世界的編程者隊伍所開發,但是同時一些大學,政府機構承包商,協會和商業公司也開發它。源代碼開放是信息技術發展引發網路革命所帶來的面向未來以開放創新、共同創新為特點的、以人為本的創新2.0模式在軟體行業的典型體現和生動註解。

共享軟體。允許他人自由拷貝並收取合理注冊費用。使用者可在軟體規定的試用期限內免費試用,再決定注冊購買與否。大部分共享版軟體都有功能和時間限制,試用期通常分為7天、21天、30天不等。而有的共享軟體還限制用戶只能安裝一次,若刪除後重新安裝將會失效。像Winzip、ACDSee等軟體就是共享軟體。

6. 我在用unity3d編一個賽車游戲,其中遇到了幾個問題:

問題1:
解決方案:
速度增加和減少用插值
在達到目標速度前 用臨時速度代替 這個是數學方法
或者將車的rigibody施加力,利用物理引擎的加速度效果來實現,這個是物理方法,具體用哪個和你讓車一動的邏輯有關

問題2:
在站點處放置一個空cube
然後將is trigger屬性打開
在碰撞裡面判斷
cube的腳本裡面記錄名次
能聽的懂嗎?
希望對你有用啊:)

7. unity3d游戲源碼怎麼學習

編程語言C#和JS,可以網上分享或開源的游戲源碼進行自學,如果想要系統性的學習可以參加培訓。

8. 求unity3d小游戲和源碼

m2h 5 個源碼 http://game.ceeger.com/forum/read.php?tid=1229 並且這個論壇裡面還有其他的源碼和資源,插件 可以看看

9. 求用C#開發的unity3D游戲源碼

m2h 5 個源碼
http://game.ceeger.com/forum/read.php?tid=1229
並且這個論壇裡面還有其他的源碼和資源,插件 可以看看

熱點內容
加密文件夾免費下載 發布:2024-11-20 10:48:47 瀏覽:772
有什麼低配置好玩的單機游戲 發布:2024-11-20 10:22:18 瀏覽:700
去哪裡可以把手機密碼清除 發布:2024-11-20 10:17:06 瀏覽:530
什麼游戲適合電腦配置不高的玩 發布:2024-11-20 09:52:02 瀏覽:235
安卓如何拷貝微信聊天記錄 發布:2024-11-20 09:51:02 瀏覽:940
php中for 發布:2024-11-20 09:48:04 瀏覽:29
安卓手機用什麼軟體防止別人蹭網 發布:2024-11-20 09:37:18 瀏覽:839
頂級asmr助眠解壓赫敏 發布:2024-11-20 09:36:34 瀏覽:429
帝瓦雷演算法 發布:2024-11-20 09:16:11 瀏覽:52
怎麼查看一個ip地址伺服器關閉 發布:2024-11-20 09:12:26 瀏覽:443