How to move character forward and also face moving direction ?
I am a newbie to unity, any help will be much appreciated.
I want to make a game where character (shown in below image) moves forward continuously. Character has to move upwards when user touches mobile screen (long touch will make character move upwards continuously) otherwise character falls down slowly due to gravity. Main theme is to avoid touching obstacles and character motion should be curvy. This is a 3D game, but character moves in x,y axis.
Till now i written below code to move the character forward and also move character upward when mobile screen touched, but it didn't worked as expected.
in update method:
transform.position += Vector3.right * Time.deltaTime * movementSpeed;
if (Input.touchCount > 0) {
if (Input.GetTouch (0).phase == TouchPhase.Began) {
// move player against the gravity
transform.position += Vector3.up * Time.deltaTime * movementSpeed;
}
if (Input.GetTouch (0).phase == TouchPhase.Ended) {
// gravity acts on the character, so character falls down
}
}
Answer by Ali-hatem · Aug 25, 2016 at 11:06 AM
public float rotationSpeed;
// UP
transform.Rotate (0, 0, rotationSpeed*Time.deltaTime);
//down
transform.Rotate (0, 0, - rotationSpeed*Time.deltaTime);
Your answer
Follow this Question
Related Questions
Unity WebGL Disable mobile warning 12 Answers
Problem when build terrain on android device 0 Answers
Black Material when camera rotate 1 Answer
Hello/How turn on phone's flash light in android devices?! 0 Answers
How to publish 400mb size apk to playstore exported from unity in android studio? 0 Answers