- Home /
Twin Stick Shooter controller
Hi,
I'm learning Unity and C#.
I try to make a Twin stick shooter game using the left and right Thumbstick of my Xbox pad. My character move correctly on the x and z axis. But the rotation of the gun on the y axis is not working correctly, it get stuck in Angles. I can't have a smooth rotation..
using UnityEngine;
using System.Collections;
CharacterMotor controller;
public Transform player_turret;
public float deadzone = 0.25f;
private Quaternion desireRotation;
void Update (){
CharacterController controller = GetComponent<CharacterController>();
moveDirection = new Vector3(Input.GetAxis("Horizontal")*speed*Time.deltaTime, 0, Input.GetAxis("Vertical")*speed*Time.deltaTime);
moveDirection = transform.TransformDirection(moveDirection);
controller.Move(moveDirection);
//right stick dead zone
Vector2 shootDirection = new Vector2(Input.GetAxis("FireHorizontal"), Input.GetAxis("FireVertical"));
if(shootDirection.magnitude < deadzone){
shootDirection = Vector2.zero;
}else
{
Vector3 shootRotation = new Vector3(shootDirection.x, 0, shootDirection.y);
desireRotation = Quaternion.LookRotation(shootRotation);
player_turret.rotation = desireRotation;
if((Time.time >= nextFireTime) && Input.GetButton("Button A")){
FireProjectile();
}
}
}
Thank you for your help :)
Comment
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
FPS Controller rotate between two points c# 2 Answers
C# Rotate GameObjects Regardless of List Size 2 Answers
How to rotate a GameObject around another object according to the mouse cursor position in C# 0 Answers
How to rotate a character controller by exactly 90 degrees with one key 1 Answer