Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
-1
Question by juliancruz87 · Feb 23, 2011 at 05:44 PM · movementcharactercontrollerfirst-person-controller

how to do FirstPersonController, does not move with the keys, else with the mouse?

how to do FirstPersonController, does not move with the keys, else with the mouse?, with a script that I have developed, and collision too operate, because if I add the component of motion and move only with the mouse, FirstPersonController not collides, and I just want to change the current keys for mouse, replace keys, a,s,d,w, and arrows, for only mouse, this is my code. please help me !!!

sing UnityEngine; using System.Collections;

public class MoveFisrtPersonMouse : MonoBehaviour {

public float velocidad = 5; public float velocityRotation = 0.3f;

private bool move = false; private float mouseX; private float mouseY;

// Update is called once per frame void Update () { if(Input.GetMouseButtonDown(0)){ move = true; mouseX = Input.mousePosition.x; mouseY = Input.mousePosition.y;

  }

  if(Input.GetMouseButtonUp(0)){
      move=false;
      mouseX = 0;
      mouseY = 0;
  }

if(move){ if(mouseX + 100 < Input.mousePosition.x){ transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y+velocityRotation,transform.eulerAngles.z); } if(mouseX - 100 > Input.mousePosition.x){ transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y-velocityRotation,transform.eulerAngles.z); } if(mouseY + 100 < Input.mousePosition.y){ transform.Translate(Vector3.forward (Time.deltaTime*velocidad)); } if(mouseY - 100 > Input.mousePosition.y){ transform.Translate(Vector3.forward (Time.deltaTime*-velocidad)); } } }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DaveA · Feb 23, 2011 at 10:00 PM

Not having looked at your code, it sounds like you could solve this by unassigning the asdf keys in the Input manager and setting up mouse equivalents there too.

Comment
Add comment · Show 3 · 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 juliancruz87 · Feb 23, 2011 at 10:45 PM 0
Share

hi thanks for replying, first of all my code has no problems, works fine, only when it is assigned to first-person-controller, the first-person-controller stops collide, only if I move it collides with the default keys ASDW . maybe you know how to operationalize the collision in spite of not moving with the keys. Thanks anyway

avatar image DaveA · Feb 23, 2011 at 11:20 PM 0
Share

If I understand you at all, it could be that using transform.Translate is ignoring collision. If you do want to be stopped by colliders, look at this: http://unity3d.com/support/documentation/ScriptReference/CharacterController.$$anonymous$$ove.html So use CharacterController.$$anonymous$$ove ins$$anonymous$$d

avatar image juliancruz87 · Mar 17, 2011 at 10:18 PM 0
Share

I get it

if someone needs move the camera tell me.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to stop first person controller from move after movement keys are not pressed anymore? 1 Answer

3D Character controller jittering when jumping against a small wall 2 Answers

best solution for topdown rpg 0 Answers

Ragdoll player character jumping unexpectedly when moved 1 Answer

Footstep sounds system with a Vr touchpad movement system 1 Answer


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