- Home /
Question by
Paramotion · Apr 20, 2017 at 04:00 PM ·
android3dtouchcontrollertouch controls
Move object with touch 3D with script
I'm creating a quick game for android, and I'm just wondering how can I translate this code I wrote (which works perfect with keyboards controls)
public float rotationSpeed = 450f;
public float walkSpeed = 5;
public float runSpeed = 8;
private Quaternion targetRotation;
private CharacterController controller;
public Camera viewCamera;
void Start ()
{
controller = GetComponent<CharacterController>();
}
void Update ()
{
ControlWASD();
}
void ControlWASD ()
{
Vector3 input = new Vector3 (Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if (input != Vector3.zero)
{
targetRotation = Quaternion.LookRotation(input);
transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle(transform.eulerAngles.y, targetRotation.eulerAngles.y, rotationSpeed * Time.deltaTime);
}
Vector3 motion = input;
motion *= (Mathf.Abs(input.x) == 1 && Mathf.Abs(input.z) == 1)? 0.7f:1;
motion *= (Input.GetButton("Run"))?runSpeed:walkSpeed;
motion += Vector3.up * -8;
controller.Move(motion * Time.deltaTime);
}
Into Android controls. I'm stuck finding a lot of 2D content, but not working in 3D. Any ideas are welcome.
Thanks in advance
Comment
Your answer
Follow this Question
Related Questions
Mutli-touch in android? 1 Answer
Dual joystick Position always resets on playing 1 Answer
Move Camera with touch (andoid) 1 Answer
Swipe menu, problem! 0 Answers