#Stabilizing mouse axis
48 messages · Page 1 of 1 (latest)
the left one uses horizontal and vertical to rotate
and the right one use mouse x and mouse y
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Flying : MonoBehaviour
{
[Header("Flying")]
public float FlightMaxSpeed;
public float FlightAcceleration;
[Header("Rotating")]
public Vector2 RotateSpeed;
public Vector2 VisualRotate;
[Header("Referances")]
public Transform Body;
private Vector2 MInput;
private Vector3 LInput;
private Rigidbody rb;
void Start(){
rb = GetComponent<Rigidbody>();
Cursor.lockState = CursorLockMode.Locked;
Application.targetFrameRate = 90;
}
void Update()
{
LInput = new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0);
Body.localEulerAngles = new Vector3(-LInput.y * VisualRotate.y, Body.localEulerAngles.y, LInput.x * VisualRotate.x);
}
void FixedUpdate(){
Vector3 Torque = new Vector3(-LInput.y * RotateSpeed.y, LInput.x * RotateSpeed.x, 0);
rb.AddRelativeTorque(Torque);
}
}
heres my code
Stabilizing mouse axis
try adding a sensitivity variable to multiply to your input
i have
I think there's also some framerate independence problems but what is Body and what is rb here? Why are you rotating both (one with transform, one with physics)?
if it works fine using Horizontal and Vertical axis just have into account that Mouse X and Mouse Y are not in the range -1...1
https://docs.unity3d.com/ScriptReference/Input.GetAxis.html
It looks like a problem more than a wrong speed multiplier here though
body is just a visual object
i rotate the parent w physics
and the white box you can see with transform
no it isnt that
then it should just move faster
but it flicks
rb is the rigidbody
im trying to make a player like this:https://www.youtube.com/watch?v=LVSmp0zW8pY
In this episode of the Prototype Series, we've experimented with creating a procedurally animated boss enemy! Let us know what you would like to see being prototyped!
⭐ Project Download https://on.unity.com/37K5j1b
⭐ Training Session https://on.unity.com/37LQfzV
Timestamps:
00:00 - Intro
00:40 - Assets Used
01:07 - Building the player camera
0...
but where you rotate it w the mouse
Well, actually I think it has a great effect in this case. Especially the following line doesn't make much sense with mouse input: Body.localEulerAngles = new Vector3(-LInput.y * VisualRotate.y, Body.localEulerAngles.y, LInput.x * VisualRotate.x);. You would likely want to increase the rotation by the mouse delta and not rotate by the amount of the mouse delt
sorry what?
if i rotate it w mouse delta
its gonna look wiers
cuz then it will maybe end up flying sideways
2 sec i can try it
or im not sure i understand what you mean
the spaceship?
yes
why do you need to change 2 different rotations? I didn't quite understand what you meant by the visual object and parent
so i have the parent object that have the camera right?
then i have the white cube you can see
it would just look completly still
so i rotate it a bit to make it look better
they explain it at 1:52
and sorry if my english doesnt make sense
I'd definitely use the inputs to only rotate the ship, not the camera. The camera movement you can do later by doing some sort of lerp follow or something similar that tries to catch up with the ships rotation. As mentioned in the video, it's just a trick that makes it look better but I don't think there is an easy way to use the same trick with mouse input.
As I said, rotating the "visual ship" is a trick they used which doesn't work so easily with mouse input. I'd definitely not rotate the visual ship model independently from the physics logic
then how would you rotate the visual ship?
I would not
I don't understand why you need it. Making the camera follow smoothly would fix the issue of ship looking still on the screen and it would work no matter how you move the ship and which input method you use
wait your right
i think ik what i can do
thanks for your help