- Home /
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.
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
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);
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
i try it and it only rotate player to diferent direction how Vector3(0,0,90);
Your answer
Follow this Question
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