- Home /
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)); } } }
}
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.
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
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
Your answer
Follow this Question
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