- Home /
Player movement isn't working
Hi, so this code here works, but as long as the "menuy" Boolean is not there. What is basically happening is that you cannot move the player until the menu animation is done playing. So I just put a simple boolean to stop the code from running till it was done.
I'm not to sure what's going on because neither the face toward the mouse or the move toward the mouse is working, yet console says it is running. Here's the code for the player:
public float speed = 4f;
public bool Menuy = true;
private Vector3 mousePos;
private Vector3 objectPos;
private float speedTurn;
private float angle;
// Update is called once per frame
void Update () {
if (Menuy == false) {
Debug.Log("WHFwf");
//Face Mouse
Vector3 mousePos = Input.mousePosition;
mousePos.z = 0f;
Vector3 objectPos = Camera.main.WorldToScreenPoint (transform.position);
mousePos.x = mousePos.x - objectPos.x;
mousePos.y = mousePos.y - objectPos.y;
var speedTurn = 500f;
float angle = Mathf.Atan2 (mousePos.y, mousePos.x) * Mathf.Rad2Deg;
Quaternion qTo = Quaternion.Euler (new Vector3 (0, 0, angle));
transform.rotation = Quaternion.RotateTowards (transform.rotation, qTo, speedTurn * Time.deltaTime);
//Move Player
var pos = Input.mousePosition;
pos = Camera.main.ScreenToWorldPoint (pos);
var dir = pos - transform.position;
rigidbody2D.AddForce (dir * speed);
}
}
In another code whenever the animation is done, it just tells this code that it is done changing "menuy" to false:
playerrrr.GetComponent<Playerrrrr>().Menuy = false;
Idealy, this should start the player to work, and then the game continues. If you have any idea why this isn't working, I'd appreciate it. Thank you
Answer by giulio-pierucci · Feb 15, 2015 at 11:25 PM
Set zero to gravity scale and disable Is Kinematic
I'm see the script move a quad right now. I have to set kinematic off, gravity 0 and $$anonymous$$enuy to false from inspector and the quad goes away
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
Distribute terrain in zones 3 Answers
Implement moveSpeed to this object script? 1 Answer
How to hold objects in third person? 1 Answer