I have taken the time to do many forum searches and come up empty handed or just missing it. What I am looking to do is to control the facing with the second joystick. Nothing to do will he camera at all. For example I have the joystick to the right, the character is rotated on his y axis 90 degrees. South would be 180 etc. I would like this to work for any rotation 1-360. But I can’t seem to figure out how to go about this.
I am new to the joysticks and iOS in general. Anyone able to throw a helpful hint or code snippet?
Ok, I have gotten the joystick to work decently, but the rotation is to choppy. Hoping to do some sort of Slerp but not the best at this yet. Here is my code for anyone looking to do a similar thing or someone that can help me smooth it out.
function FaceAttackDirection()
{
if(rotateJoystick.position.x != 0 || rotateJoystick.position.y != 0) {
var rotationDirection = Vector3(rotateJoystick.position.x, 0 , rotateJoystick.position.y);
rotationDirection = rotationDirection.normalized;
//Create a rotation facing that point.
var rotation = Quaternion.LookRotation(rotationDirection);
transform.rotation = rotation;
}
}
I did this but in a strange way that worked out great. I just had an invisible object that was a child of the character. the relative position of the invisible object would move front back, left and right and all the diagonals based on the joystick moves. then i had the character look at the invisible object. this worked out great and was very smooth.
@GameFaceMe, how did you send the variables of the stick to influence the position of your object since the X and Y are between -1 and 1?
@marjan, what the joystick does in that tutorial in what I would need I imagine. Although it would be an entire overhaul of my code to change to how they are doing it. I’ll keep reading their code to see if i can find something.
Does anyone know how to just slerp the code I posted? I’d rather just use the way I found as it is muc less code and I understand it so far. Adding that much code copy/paste and getting it to work…well I feel that is beyond my level of understanding to implement corretly.
I just take the player’s position and add the rotation joystick x and y to it and assign that to the invisible “look at” object’s position. here’s the code:
I worked on a joystick for my current game, here it is, and how the player interprets the joysticks for movement and looking (if the look joystick is not in use then the player will look in the direction he is moving). These joysticks are clamped in circles and give full 360 movement, not 8 directional (used to be like that but I needed more precision so I changed it).