logo
Khóa học lập trình game server - smartfox - game đa người chơi Học lập trinh game online 3dvietpro Sửa chữa và thiết kế website .net
Welcome Guest! To enable all features please Đăng nhập or Đăng ký.

Thông báo

Icon
Error

Tùy chọn
Xem
Xem bài viết cuối Go to first unread
admin  
#1 Đã gửi : 30/08/2014 lúc 02:34:48(UTC)
admin

Danh hiệu: Administration

Nhóm:
Gia nhập: 19-08-2014(UTC)
Bài viết: 145

Được cảm ơn: 7 lần trong 6 bài viết

Mọi người nghiên cứu WheelCollider, motorTorque, Rotate đựa theo code chia sẻ này nhé


using UnityEngine;
using System.Collections;

public class new_motion : MonoBehaviour
{

public Transform vathe;
public AudioClip Clip1;

public WheelCollider rearWheel1;
public WheelCollider rearWheel2;
public WheelCollider frontWheel1;
public WheelCollider frontWheel2;
public BoxCollider collCar;
public Transform wheelFL;
public Transform wheelFR;
public Transform wheelRL;
public Transform wheelRR;
private bool canSteer ;
private bool canDrive ;
private bool running ;
int steer_max = 20;
int motor_max = 200;
int brake_max = 100;
private float steer = 0;
private float forward = 0;
public float back = 0;

private float motor = 0;
private float brake = 0;
public bool reverse = false;
private float speed = 0;
Vector3 dragMultiplier = new Vector3 (1, 5, 1);
private float initialDragMultiplierX = 10.0f;




void Start ()
{
initialDragMultiplierX = dragMultiplier.x;

}

// Update is called once per frame
void Update ()
{
Vector3 relativeVelocity = transform.InverseTransformDirection (rigidbody.velocity);

FixedUpdate ();



}

public Transform CameraBack;

void FixedUpdate ()
{
// speed of car
speed = rigidbody.velocity.sqrMagnitude;

//print (relativeVelocity + "----" + speed);



steer = Mathf.Clamp (Input.GetAxis ("Vertical"), -1, 1);

forward = Mathf.Clamp (Input.GetAxis ("Vertical"), 0, 1);

back = -1 * Mathf.Clamp (Input.GetAxis ("Vertical"), -1, 0);

//print (Input.GetAxis("Vertical") + "-back:" + back);

if (speed == 0) {
if (back > 0) {
reverse = true;
}
if (forward > 0) {
reverse = false;
}
}


if (reverse) {
motor = -1 * back;
brake = forward;
} else {
motor = forward;
brake = back;
}


//print ("brake:" + brake);


if (Input.GetKey(KeyCode.Space)) {

running = true;
} else {

running = false;

}

if (running) {
rearWheel1.motorTorque = motor_max * motor;
rearWheel2.motorTorque = motor_max * motor;
} else {
rearWheel1.motorTorque = 100 * motor;
rearWheel2.motorTorque = 100 * motor;
}
rearWheel1.brakeTorque = brake_max * brake;
rearWheel2.brakeTorque = brake_max * brake;


frontWheel1.steerAngle = Input.GetAxis ("Horizontal") * 40;
frontWheel2.steerAngle = Input.GetAxis ("Horizontal") * 40;

if(Input.GetKey(KeyCode.LeftArrow))
{
print("banh trai");
frontWheel1.transform.localRotation = Quaternion.Euler (0.009044712f, -0.07808232f, -0.03903911f);

}



wheelFR.Rotate (frontWheel1.rpm * 6 * Time.deltaTime, 0, 0);
wheelFL.Rotate (frontWheel2.rpm * 6 * Time.deltaTime, 0, 0);
wheelRR.Rotate (rearWheel1.rpm * 6 * Time.deltaTime, 0, 0);
wheelRL.Rotate (rearWheel2.rpm * 6 * Time.deltaTime, 0, 0);





}



bool bl = false;

void OnTriggerEnter (Collider other)
{
if (other.gameObject.name == "Cube") {
bl = true;


}
}




}
thanks 1 người cảm ơn admin cho bài viết.
boy289990 trên 30-08-2014(UTC) ngày
Bạn bình luận ngay tại đây
Ai đang xem chủ đề này?
Guest
Di chuyển  
Bạn không thể tạo chủ đề mới trong diễn đàn này.
Bạn không thể trả lời chủ đề trong diễn đàn này.
Bạn không thể xóa bài của bạn trong diễn đàn này.
Bạn không thể sửa bài của bạn trong diễn đàn này.
Bạn không thể tạo bình chọn trong diễn đàn này.
Bạn không thể bỏ phiếu bình chọn trong diễn đàn này.

Powered by YAF 2.1.0 | YAF © 2003-2024, Yet Another Forum.NET
Thời gian xử lý trang này hết 0.074 giây.