I've already tried to ask this question some days ago but nobody has answered yet, I'll try to ask this again in hope that anyone could help me.
Hello, I've been trying to make it so that my player gets propelled to the opposite direction to where the user makes a mouse click. The following code was applied to the player. I can't get it to work even though the DrawLine debug works and the Debug.log for 2DForceVector works too.
Hopefully you can help me.
Thanks in advance.
var movementMaxVelocity : float = 10;
var jumpSpeed : float = 3;
var movementForce : float = 10;
var mouseVectorPosition : Vector2;
var playerVectorPosition : Vector2;
var 2DForceVector : Vector2;
function Update () {
mouseVectorPosition= Camera.main.ScreenToWorldPoint(Input.mousePosition);
playerVectorPosition = transform.position;
2DForceVector = (mouseVectorPosition - playerVectorPosition).normalized;
rigidbody2D.AddForce(2DForceVector * movementForce * -1);
}
↧