I would liek to start out by explaining that i am New to Scripting.
I am trying to make a ‘Character controller’, I know there is one in unity already, But it is a challenge to create my own one, and it wil help me pick things up along the way,
I have done this code and hoped it would work, But it just teleports me to X:0 Y:0 Z:5e-05
I thought that this code would move the box along the local Z axis at 5 unity per second, Apparently i was wrong.
Please help me figure this out, Thanks!
var normSpeed : float = Time.deltaTime * 5;
var sboostSpeed : float = Time.deltaTime * 8;
function Update () {
if(Input.GetKeyDown ("w")){
transform.localPosition = Vector3(0, 0, normSpeed);
}
}
If you want to move, you have to add the speed you moved, not simply move to the speed you moved (which doesn’t make much sense!). I also showed an appropriate usage of Time.deltaTime.
transform.localPosition += Vector3(0, 0, normSpeed) * Time.deltaTime; moves me on the Worlds Z axis, doesn’t localPosition mean the the Vector3 in relation to the Object, and not World?
i tried Input.GetKeyDown, but then i get the error “Operator ‘*’ cannot be used with a left hand side of type ‘UnityEngine.Vector3’ and a right hand side of type ‘boolean’” ?
Exactly what it says. You cannot times a Vector by a boolean. Use the script reference and take a look at the result of Input.GetAxis and Input.GetAxisDown.
transform.position += transform.forward * Input.GetAxis(“Vertical”) * normSpeed * Time.deltaTime; it moves once when i press it, How would i make it keep moving while i hold it?