- Home /
Will not shoot, also my character will only move side ways.
var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab: Transform;
function update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,GameObject.Find("SpawnPoint").transform.position,Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
}
}
@script RequireComponent(CharacterController)
Answer by Seth-Bergman · Jul 22, 2012 at 03:25 PM
fixed a few errors:
var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab: Transform;
function Update () //capitalized
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
//var forward = transform.TransformDirection(Vector3.forward);
var forward = transform.forward;
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Jump"))
{
var bullit = Instantiate(bullitPrefab,GameObject.Find("SpawnPoint").transform.position,Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);//intended direction?
}
}
@script RequireComponent(CharacterController)
I suspect the bullet is shooting, may be going so fast you don't see it though. See if it appears (the bullet) in the hierarchy panel when you shoot, you may not see it in the scene, but it will show up in the hierarchy panel. Or, remove the AddForce line to make sure it's appearing
If the character is moving sideways, he may have been exported from the animation engine that way, with the wrong orientation.
re-export, or you can reset it in the Start function:
function Start(){
transform.forward = new Vector3.right;//or
transform.forward = new Vector3.left; // or whatever Vector3
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Error UCE0001 ";"Expected 2 Answers
play music on key press 1 Answer
play music on key press 1 Answer
each enemy have different damage amount, how to calculate the hp remain??? 1 Answer