#Stabilizing mouse axis

48 messages · Page 1 of 1 (latest)

toxic void
#

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

shadow socket
#

try adding a sensitivity variable to multiply to your input

toxic void
#

i have

void warren
#

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)?

shadow socket
void warren
#

It looks like a problem more than a wrong speed multiplier here though

toxic void
#

i rotate the parent w physics

#

and the white box you can see with transform

toxic void
#

then it should just move faster

#

but it flicks

toxic void
#

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...

▶ Play video
#

but where you rotate it w the mouse

void warren
# toxic void no it isnt that

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

toxic void
#

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

toxic void
void warren
#

why do you need to change 2 different rotations? I didn't quite understand what you meant by the visual object and parent

toxic void
#

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

void warren
# toxic void it would just look completly still

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.

toxic void
#

the camera works perfectly

#

its only the visual rotation that flicks

void warren
# toxic void the camera works perfectly

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

toxic void
void warren
#

I would not

toxic void
#

alr thanks for trying to help

#

ill have to find another way then

void warren
toxic void
#

i think ik what i can do

#

thanks for your help