- Home /
Question by
zak666 · Sep 21, 2017 at 06:34 AM ·
mouseaddforceridgidbody
ADD-FORCE player fly by mouse?
hey gang Trying to put y Player controller to use rigidBodies to players can fly into walls and things, trying to Figure out "Fly by mouse" Using the mouse to fly around. (third person space-shooter) I managed to do it with translate but Trying to make it work with rigidBodies so i can have collisions.
{
public int maxSpeed = 70;
public int minSpeed = 10;
public float rotationSpeed = 150;
public int currrentSpeed = 30;
public Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
}
void LateUpdate()
{
if (photonView.isMine == true) {
// Boost Break Controll:------------------------------------------------
if (Input.GetButton ("Boost")) {
currrentSpeed = 90;
} else{
currrentSpeed = 70;
}
//----------------------------------------------------------------------
if (Input.GetButton ("Break")) {
currrentSpeed = 20;
} else{
currrentSpeed = 70;
}
//----------------------------------------------------------------------
//Fly By Mouse.
// Use AddForece for Physics.
rb.AddForce(transform.forward * currrentSpeed);
}
}
}
Comment
Answer by unit_nick · Sep 21, 2017 at 06:00 PM
I would make the force you add to the rb relative to the distance from the player to the mouse
I would expect you would want to square the value.
You may also want to multiply the value before it is squared if it isn't responding fast enough.
At the moment you are only adding forwards momentum to the player. How do you guide him? I would expect you to point the player towards the mouse.
Your answer
