• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by computerzot · Aug 29, 2012 at 06:06 PM · controllermove

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image computerzot · Aug 29, 2012 at 08:11 PM 0
Share

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 ^^

avatar image Mander · Aug 29, 2012 at 08:21 PM 0
Share

so its not working? xD i dont understand

avatar image
0

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.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mander · Aug 29, 2012 at 08:23 PM 0
Share

a simple characte controller should work. and the other objects need a collider thats it

avatar image computerzot · Aug 29, 2012 at 08:34 PM 0
Share

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

avatar image Mander · Aug 29, 2012 at 08:42 PM 0
Share

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

avatar image computerzot · Aug 29, 2012 at 08:52 PM 0
Share

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?

avatar image Mander · Aug 29, 2012 at 08:57 PM 0
Share

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

avatar image
0

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...

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How is the Move() function constrained by collisions? 2 Answers

Very Simple Left and Right Movement Script [OR] disable dravity on CharacterController? 2 Answers

How do I listen for Input from joystick/buttons on a controller? 1 Answer

iOS Tap to move?? 2 Answers

MMD How to export model and animations to Unity as 3rd person controller? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges