- Home /
transform.down not working.
I'm trying to run the following code:
if (Input.GetKeyDown (KeyCode.S) && groundScript.isGrounded == false) {
rig.AddForce (transform.down * jumpHeight);
}
But after saving, I'm receiving the following error: Assets/Scripts/Jump.cs(23,28): error CS1061: Type UnityEngine.Transform' does not contain a definition for
down' and no extension method down' of type
UnityEngine.Transform' could be found. Are you missing an assembly reference?
The thing is just above that line of code I have:
if (Input.GetKeyDown (KeyCode.Space) && groundScript.isGrounded == true) {
rig.AddForce (transform.up * jumpHeight);
}
And it is working perfectly fine. .down is highlighted in red and doesn't show as a possible Vector3. Any ideas why?
Answer by Dragate · Oct 23, 2017 at 01:14 PM
https://docs.unity3d.com/ScriptReference/Transform.html
There is no transform.down. But you can easily calculate it since it's the opposite of transform.up.
rig.AddForce (-transform.up* jumpHeight);
Answer by FabDynamic · Oct 23, 2017 at 09:25 PM
One way to do it:
Vector3 transformDown = transform.up * -1.0f;
Why multiplying the vector by "-1.0f" when an unary $$anonymous$$us is shorter and faster?
Only in order to be utterly and transparently clear to the reader what is going on. You are right that it doesn't matter.
Answer by theLittleSettler · Oct 23, 2017 at 01:12 PM
Well, its a bit silly, but there really isn't a down (or left, or backwards) defined. I guess its just Transform doesn't have them (though Vector3 does). Odd they would define them in one and not the other.