- Home /
move character controller with collision
Hi, i want to move a character (which has a rigidbody). (left, right, up and down). But I dont want to move using the keyboard. (i have a ps2 console connected with arduino, that sends the commands to unity). i want to use transform.position like this :
var forward : Vector3 = transform.TransformDirection(Vector3.forward);
if (up == true){ Character.transform.position += Character.transform.forward * speed; }
so, if i rotate my character and move forward, i'm moving forward from the characters perspective. but if you use transform.position, the colliders dont work. My character can walk true the walls.... Now if you use something like :
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if(up == true){ moveDirection.z = speed; }
the collision works, and i cant walk true walls. But now if I rotate and go forward, i'm not going forward from the characters perspective. I just move on the Z axis.
So how can i use the transform.position,, but keep the colliders?
Answer by Mander · Aug 29, 2012 at 08:07 PM
remove `if(up == true){ moveDirection.z = speed;`
didn't test but try this.
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
edit: controller.Move(moveDirection * Time.deltaTime);
this works, but i have to check on each movement. So i have 4 IF's. One for left, right, up and down. This is because i get the input not from keyboard, but from arduino true Serial Port.
So i realy have to say when to go a specific direction, from the perspective of the character...
hope i'm making myself clear. $$anonymous$$y english isnt that great ^^
Answer by computerzot · Aug 29, 2012 at 08:21 PM
I'm having a bit the same problem like here :
http://answers.unity3d.com/questions/48770/transformposition-with-box-collider.html
The object that moves, has to collide with everything else in the world. (all other stuff are c4d imports with mesh colliders). But i dont need the methods like OnControllerColliderHit. I dont have to do anything with these collision. Only that the object doesnt go true walls etc.
a simple characte controller should work. and the other objects need a collider thats it
i have a character controller. And all other object have a mesh collider. If i use :
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if(up == true){ moveDirection.z = speed;}
The object cant move true the walls.
But when i rotate, and move forward after the rotation. The object moves still in the same direction as before the rotation. (its hard to explain :p)
So i want to use Character.transform.position += Character.transform.forward * speed;
to move my object. But then the object goes true the walls...
btw, ty for the help already $$anonymous$$ander ;-)
use the controller.move
try adding this line after the previous answer this is the function to move a character controller its input is a Vector3 controller.$$anonymous$$ove(moveDirection * Time.deltaTime);
I have this line at the bottom of the script. (forgot to copy past it...)
But how do you set the right direction? If you want to go left for example... I still have to check the direction, not?
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
with that variable u check the inputs on the keyboard u should configure ur inputs at.
edit -> project settings -> input on the inspector window configure ur type to joystick axis
Answer by computerzot · Aug 29, 2012 at 09:35 PM
i dont think this is possible. The values i get for direction from Arduino are just strings. "left", "right", "up", "down". I read these strings, and if i receive "up", the up boolean get sets on true...
I dont know if i can set these values in the input manager...
Your answer
Follow this Question
Related Questions
Rotate Controller and move rotation direction ? 0 Answers
How to move character by command? 1 Answer
Why does Controller.move work fine in editor, but not in build since 4.0 upgrade? 1 Answer
i want to move a ball on z axis and jump on y axis , 2 Answers
Character rig controllers and hierarchy mismatch when importing from 3DsMax 1 Answer