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
0
Question by SVKsuli · Jul 23, 2014 at 06:11 AM · playermousepositioncontrol

mouse control with slower rotation

hi, i need help with completion of my player control script. i try change rotation control from keycode to mouse but now i dont know how make rotation slowly. here is my script:

 #pragma strict
 
 var speed = 0f;
 var score = 0;
 var maxspeed : float;
 var acceleration : float;
 var SpawnPos : Vector3;
 static var Plife = 3f;
 var animator: Animator;
 var mousepos : Vector3;
 
 function Start () {    
 }
 
 function Update () {
 
     var objectPos = Camera.main.WorldToScreenPoint(transform.position);
     var mousepos = Input.mousePosition - objectPos; 
     transform.rotation = Quaternion.Euler (Vector3(0,0,Mathf.Atan2 (mousepos.y,mousepos.x)* Mathf.Rad2Deg)); 
     transform.Rotate(Vector3(0,0,-90));    //i need to make this rotate slower.
     
     if(Plife <= 0f){
         transform.position = SpawnPos;
         Plife = 3f;
         score -= 1;
         speed = 0f;
         NewPlShooting.spawnDelay = 0.1f;
     }
     
     GUILayerScript.speed = speed;
     GUILayerScript.life = Plife;
     GUILayerScript.Pscore = score;
     GUILayerScript.position = transform.position;
     NewPlShooting.Pspeed = speed / 40;
     ParticleControler.speed = speed;
     
     if(Input.GetKey(KeyCode.C)) {
         if(GetComponent(CircleCollider2D).enabled == false) {
             GetComponent(CircleCollider2D).enabled = true;
         }
         else if(GetComponent(CircleCollider2D).enabled == true) {
             GetComponent(CircleCollider2D).enabled = false;
         }
     }
 }
 
 function FixedUpdate() {
     if(Input.GetKey(KeyCode.W)) {
         rigidbody2D.velocity = transform.up * speed * Time.deltaTime;
         animator.SetBool("stop", false);
         animator.SetBool("stop2", false);
         if(speed < maxspeed) {
             speed += acceleration;
         }
     }    
     else if(Input.GetKey(KeyCode.S)) {
         rigidbody2D.velocity = transform.up * speed * Time.deltaTime;
         if(speed > -400) {
             speed -= acceleration * 2;
         }
     }
     else {        
         rigidbody2D.velocity = transform.up * speed * Time.deltaTime;
         animator.SetBool("stop", true);
         animator.SetBool("stop2", true);
         if(speed > 0) {    
             speed -= 1f;
         }
         else if(speed < 0) {
             speed += 1f;
         }
     }
 }
 
 function OnCollisionEnter2D(col : Collision2D){
     if (col.gameObject.tag == "bullet1") {    
         Plife -= 1f;
     }
 }

thx for help.

Comment
Add comment · Show 2
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 SVKsuli · Jul 24, 2014 at 03:33 AM 0
Share

i now try change this code:

  var objectPos = Camera.main.WorldToScreenPoint(transform.position);
     var mousepos = Input.mousePosition - objectPos; 
     transform.rotation = Quaternion.Euler (Vector3(0,0,$$anonymous$$athf.Atan2 (mousepos.y,mousepos.x)* $$anonymous$$athf.Rad2Deg)); 
     transform.Rotate(Vector3(0,0,-90));    //i need to make this rotate slower.
  

for this:

 var objectPos = Camera.main.WorldToScreenPoint(transform.position);
     var mousepos = Input.mousePosition- objectPos; 
     var rotation = Quaternion.Euler (Vector3(0,0,$$anonymous$$athf.Atan2 (mousepos.y,mousepos.x)* $$anonymous$$athf.Rad2Deg)); 
     transform.rotation = Quaternion.Slerp(transform.rotation,rotation, Time.deltaTime * 2);
     

it work better but it still have bug, because player look to wrong direction(when mouse is up player look to left). i thought i can it fix with transform.Rotate(Vector3(0,0,-90)); but when i write this to new version player still rotate around and i cant control it. Does anyone know how can i fix it? thx

avatar image SVKsuli · Jul 24, 2014 at 08:21 PM 0
Share

ok i made it thx for help :D

 var objectPos = Camera.main.WorldToScreenPoint(transform.position);
     var mousepos = Input.mousePosition- objectPos; 
     var rotation = Quaternion.Euler (Vector3(0,0,$$anonymous$$athf.Atan2 (mousepos.y,mousepos.x)* $$anonymous$$athf.Rad2Deg -90)); 
     transform.rotation = Quaternion.Slerp(transform.rotation,rotation, Time.deltaTime * 2); 
     

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Issah · Jul 23, 2014 at 12:46 PM

Hi

 var mousepos = Input.mousePosition/SMOOTH - objectPos;

try smooth = 0.5 and the rotation by mousePos will be slowly, you can use smooth to make an sensitivity option.

Hope it will help

Comment
Add comment · Show 1 · 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 SVKsuli · Jul 23, 2014 at 01:02 PM 0
Share

i try it and it only rotate player to diferent direction how Vector3(0,0,90);

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Player jumping into object 1 Answer

How do you make a game object into a controllable player? 2 Answers

How to align x-axis movements with mouse x movement. 0 Answers

Giving individual players control of specific units in an RTS/MOBA 0 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