x


how to move my character?

I am making a ninja game and i made a pretty cool ninja using the basic objects in unity because i don't have a graphic design program (or the money for one) to do it. now because the colliders are clashing when i click the forward button i fly in the air. i tried changing the size of the the colliders so they were not touching and moving the objects so they did not touch the other game objects but i still slowly move up. this is my walking script.

var speed= 6.0;
var rotateSpeed = 3.0;
var runningSpeed= 10.0;
var strafeSpeed = 0.1;

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);

}
more ▼

asked Jan 11 '11 at 05:11 AM

Tyler Alvis gravatar image

Tyler Alvis
215 42 50 57

Can you give some more details about what objects are in your scene? For example what are you using for the character and floor? And what colliders are attached to each. This will make it easier to recreate your scene and debug the problem.

Feb 07 '11 at 03:01 PM GesterX
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I have also an answer, that it more Easy. In the game I am creating now, i used a game object. I did so the game object was to be a prebab or what the name is. And so, i added a camera, a characher controller. And now It can be constrolled as you want to.

more ▼

answered Feb 22 '12 at 10:00 PM

SpacePlanet gravatar image

SpacePlanet
1 1 3 3

(comments are locked)
10|3000 characters needed characters left

Try using transform.forward rather than TransformDirection(Vector3.forward). You might want to consider putting it directly in the SimpleMove or creating another variable other than "forward" (I get nervous when using variable names that are already in use on other Components)

Also, your character will move at different speeds depending on your framerate. Try multiplying your move by Time.deltaTime in order to keep the movement framerate-independent.

EDIT

var speed: float= 6.0;
var rotateSpeed: float = 3.0;
var cControl: CharacterController;

function Awake (){
    cControl = GetComponent(CharacterController);
}

function Update () 
{

    var direction: Vector3 = Vector3 (0, Input.GetAxis ("Horizontal") * rotateSpeed* Time.deltaTime, 0);
    var movementSpeed: float = Input.GetAxis ("Vertical")*speed*Time.deltaTime;

    transform.Rotate(direction);
    cControl.SimpleMove(transform.forward*movementSpeed);

}

Try the above. Let me know if you still have the same problem... there's one more thing I can think of trying...

more ▼

answered Jan 11 '11 at 05:18 AM

The_r0nin gravatar image

The_r0nin
1.4k 9 14 30

could you just script that becasue i changed the line to: var forward = transform.forward; and i still fly, i think it is because of the colliders

Jan 11 '11 at 05:52 AM Tyler Alvis
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x323
x5

asked: Jan 11 '11 at 05:11 AM

Seen: 1182 times

Last Updated: Feb 22 '12 at 10:00 PM