Unity 5 doesn't detect some positions in Vector3
Hello guys! Im trying to acces to Vector3.back but i dont know why it doesn't work, but using Vector3.forward, left, up, these are working correctly. What is the error here? Im using Unity 5.4.0b17 (64-bit) Personal.
The code: using UnityEngine; using System.Collections;
public class Balance : MonoBehaviour {
public int StandForce;
public float horizontalSpeed = 2.0f;
public float verticalSpeed = 0.0f;
public KeyCode crouch;
public KeyCode forw;
public KeyCode backw;
void Start(){
BoxCollider collider = gameObject.GetComponent ("BoxCollider") as BoxCollider;
}
void Update(){
float h = horizontalSpeed * Input.GetAxis ("Mouse X");
float v = verticalSpeed * Input.GetAxis ("Mouse Y");
transform.Rotate (v, h, 0);
if (Input.GetKey (forw)) {
Vector3 forward = transform.TransformDirection (Vector3.forward) * 1;
GetComponent<Rigidbody> ().AddForce (transform.forward * StandForce, ForceMode.Acceleration);
GetComponent<Rigidbody> ().useGravity = true;
}
if (Input.GetKey (backw)) {
Vector3 back = transform.TransformDirection (Vector3.back) * 1;
GetComponent<Rigidbody> ().AddForce (transform.back * StandForce, ForceMode.Acceleration);
GetComponent<Rigidbody> ().useGravity = true;
}
if (Input.GetKeyDown (crouch)) {
GetComponent<Collider>().GetComponent<BoxCollider> ().enabled = false;
}
if (Input.GetKeyUp (crouch)) {
GetComponent<Collider>().GetComponent<BoxCollider> ().enabled = true;
}
}
void OnTriggerStay(){
Vector3 up = transform.TransformDirection (Vector3.up) * 1;
GetComponent<Rigidbody> ().AddForce (transform.up * StandForce, ForceMode.Acceleration);
GetComponent<Rigidbody> ().useGravity = true;
}
}
Images:
What does the script? "some spam"
What exactly is it doing? Nothing at all? Or just...weird behavior?
Also, your images are showing up as forbidden. Use a public listing site.
$$anonymous$$akes a rigidbody balance/float when enter on trigger, i used a box collider, works similar a raycast. Then with some keys it can move in air, impulse the rigidbody and nothing more. But in the values i used normal floats and negative floats, it works, but i dont know why transform.back doesn't work. I cant remember other orientations that doesn't work.
but i dont know why transform.back doesn't work
"Doesn't work" is a little misleading here. It's a compiler error, because Transform just has no member by that name. But (-transform.forward) should work.
BTW: It would be nice if you remove lines that do nothing from your code before posting. It makes it easier for other people to understand the code.
Your answer
Follow this Question
Related Questions
How to convert an inputfield's string to an int? (C#) 1 Answer
[C#] The left-hand side of an assignment must be a variable, a property or an indexer 0 Answers
I have an error on a C# script @username 2 Answers
Nav Mesh Problem with SetDestination 1 Answer
Using a reference for another script in a method issue. 0 Answers