- Home /
My Character moving too slow - 2D C#
My problem is that i have a script that i attach to my character ( A simple box ) and i want it to move across the screen to the opposite side, after a certain amount of time. But the problem is that after the time ( 2 seconds ), the box moves VERY slowly. Any ideas? Here is my code. Thanks
using UnityEngine;
using System.Collections;
public class RightSideObjects : MonoBehaviour {
public float movementSpeed;
public int waitingTime;
void Start(){
StartCoroutine (WaitAndPrint (2.0f));
}
IEnumerator WaitAndPrint(float waitTime) {
yield return new WaitForSeconds (waitTime);
// rigidbody.AddForce(Vector3.left * movementSpeed);
rigidbody.AddForce(Vector3.left * movementSpeed);
}
}
$$anonymous$$y first instinct would be to say that you're simply adding a very small force. Try setting movementSpeed to something like 1000, or 2000.
Because you're trying to manipulate the object with unity physics, the ammount it moves depends very much on the objects weight and drag (basically its size), so a smaller object would move faster with the same force (in your case movementSpeed) applied to it.
So either modify the objects position directly
transform.position += Vector3.left * Time.deltaTime * movementSpeed;
(this will move all objects the same ammount, regardless of their physical properties)
OR, add a bigger force (movementSpeed) :)
Hahah thanks man, it was the first thig, i have the speed at 10 xD, so i changed it 600 which was the perfect amount for me Thank you so much dude :D
Your answer
Follow this Question
Related Questions
AddForce on Rigidbody with CharacterJoint Doesn't Work 0 Answers
Add force on objects from a specific location in space 2 Answers
AddForce not influenced by rotation 1 Answer
Script problem 2 Answers