Quantcast
Channel: Questions in topic: "side scroller"
Viewing all articles
Browse latest Browse all 72

Can only move forward or back, no left or right.

$
0
0
This is really strange, I am very very new to programming so be patient and bear with me please. As the title says I can only move my character forward or back and not sideways, the funny thing about this is that I don't want him to move forward or back I want only side ways. It is the basic 2d space shooter you would expect. I have tried two sets of code, first is below: `var speed : float = 3; var projectile_prefab: GameObject; function Update () { var translationX : float = Input.GetAxis ("Horizontal") * speed; var translationZ : float = Input.GetAxis ("Horizontal") * speed; translationX *= Time.deltaTime; translationZ *= Time.deltaTime; transform.Translate (translationX, 0, translationZ); if(Input.GetKeyDown("space")) Instantiate(projectile_prefab); }` The other set of code I tried was: `var moveSpeed = 1.0; var turnSpeed = 1.0; function Update() { /* if(Input.GetButtonDown("Jump")) { transform.position.z += 1.0; } */ if(Input.GetButton("Forward")) { transform.position += transform.forward * moveSpeed * Time.deltaTime; } if(Input.GetButton("Backward")) { transform.position += -transform.forward * moveSpeed * Time.deltaTime; } if(Input.GetButton("Left")) { transform.eulerAngles.y += -turnSpeed * Time.deltaTime; } if(Input.GetButton("Right")) { transform.eulerAngles.y += turnSpeed * Time.deltaTime; } } if(Input.GetKeyDown("space")) Instantiate(projectile_prefab); }` I cant understand why either of these don't work. Any help is greatly appreciated.

Viewing all articles
Browse latest Browse all 72

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>