คือผมกำลังจะทำเกมครับ แต่ติดตรง
[Spoil] คลิกเพื่อดูข้อความที่ซ่อนไว้ if (Input.GetButtonDown("Jump"))
{
rigidbody.AddForce(transform.up * jumpForce);
}
}
void FixedUpdate() {
rigidbody.MovePosition(rigidbody.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
}
อะครับ มันเป็นแบบว่าขึ้นขีดๆสีแดงใต้ rigidboy.MovePosition(rigidbody.position---- อะครับ พอดีผมพึ่งหัดเขียนวันนี้วันที่สองครับ เรียนในยูทูป
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PLayer : MonoBehaviour {
public float mouseSensitivityX = 250f;
public float mouseSensitivityY = 250f;
public float walkSpeed = 8f;
public float jumpForce = 220;
Transform cameraT;
float verticalLookRotation;
Vector3 moveAmount;
Vector3 smoothMoveVelocity;
void Start () {
cameraT = Camera.main.transform;
}
void Update () {
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivityX);
verticalLookRotation += Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivityY;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -60, 60);
cameraT.localEulerAngles = Vector3.left * verticalLookRotation;
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
Vector3 targetMoveAmount = moveDir * walkSpeed;
moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
if (Input.GetButtonDown("Jump"))
{
rigidbody.AddForce(transform.up * jumpForce);
}
}
void FixedUpdate() {
rigidbody.MovePosition(rigidbody.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
}
}
Need help krub มีใครช่วยผมแก้โค้ดนี้ได้บ้าง
using System.Collections.Generic;
using UnityEngine;
public class PLayer : MonoBehaviour {
public float mouseSensitivityX = 250f;
public float mouseSensitivityY = 250f;
public float walkSpeed = 8f;
public float jumpForce = 220;
Transform cameraT;
float verticalLookRotation;
Vector3 moveAmount;
Vector3 smoothMoveVelocity;
void Start () {
cameraT = Camera.main.transform;
}
void Update () {
transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * Time.deltaTime * mouseSensitivityX);
verticalLookRotation += Input.GetAxis("Mouse Y") * Time.deltaTime * mouseSensitivityY;
verticalLookRotation = Mathf.Clamp(verticalLookRotation, -60, 60);
cameraT.localEulerAngles = Vector3.left * verticalLookRotation;
Vector3 moveDir = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")).normalized;
Vector3 targetMoveAmount = moveDir * walkSpeed;
moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, .15f);
if (Input.GetButtonDown("Jump"))
{
rigidbody.AddForce(transform.up * jumpForce);
}
}
void FixedUpdate() {
rigidbody.MovePosition(rigidbody.position + transform.TransformDirection(moveAmount) * Time.fixedDeltaTime);
}
}