Question by
geenzie · Aug 02, 2020 at 09:56 PM ·
mobilemovement scriptnot workingmoveposition
Movement Script for Mobile Game Using rb.MovePosition Not Working
I have tried changing the script a number of times, and I have gotten some advice on what issues I might have had, however, when I test the script, I am still unable to move my player. I would greatly appreciate any advice or help.
{ public float speed = 10.0f;
public Rigidbody rb;
private Vector3 position;
private Touch touch;
private float width;
private float height;
void Start()
{
rb = this.gameObject.GetComponent<Rigidbody>();
width = Screen.width;
height = Screen.height;
}
void FixedUpdate()
{
if(Input.touchCount > 0)
{
touch = Input.GetTouch(0);
if(touch.phase == TouchPhase.Moved)
{
Vector2 pos = touch.position;
pos.x = (pos.x - width) / width;
pos.y = (pos.y - height) / height;
position = new Vector3(-pos.x, pos.y, 0.0f);
rb.MovePosition((Vector3)transform.position + transform.forward * speed * Time.deltaTime);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Why is my ball flying away? 0 Answers
How do I make an object move in the direction its facing? 1 Answer
Problems with mobile touch movements. 0 Answers