#For me there is not enough info for this

1 messages Β· Page 1 of 1 (latest)

azure needle
#

hey

granite oyster
#

So the fact that it changes back is the jitter?

azure needle
#

yeah. sorry, bad usage of the word.

signal fiber
#

i suspect your jittering is coming from imperfect jittery movement by the physical mouse, what do you think?

granite oyster
#

If you clicked once, and in your GetMouseButtonUp sequence you always set the animation to IsGoingLeft to true. So after 1 click you always go either left or right, never straight.

azure needle
#

so mousebuttonup is the prob? πŸ€”

granite oyster
#

No your logic is πŸ˜›

#

Do you understand what I'm trying to say?

#

That you can never go forward again after pushing the mouse button?

azure needle
#

not really.

granite oyster
#

That's the problem

#

Alright, lets change it around then.
How do you go back to the forward animation after clicking the mousebutton?

azure needle
#

okok. now i get it

#

there is no condition for forward anim to play

granite oyster
#

Very good

azure needle
#

I just realized that i didnt assign movingleft to false when MouseButtonUp. FML πŸ€¦β€β™‚οΈ

granite oyster
azure needle
#

when it reaches full left or right, the anims are a bit off.

#

going right animation is playing even though i am pulling the mouse towards left and then changing to left anim. anyway around this?

granite oyster
#

Also if you go right a bit and then left, first the right anim sequence plays fully and then the left one. There is also no animation from right to left, only from middle to left.

#

There are lot's of reasons why using animations like this will give you a headache πŸ˜›

#

No idea why you use anims for this, why not set the rotation?

#

That's why I said that

azure needle
#

ik. I was told to use anims on this server.

granite oyster
#

By whom?

azure needle
#

I was doing this before i opted for anims.

#

Quaternion targetRotation = Quaternion.LookRotation(transform.position); handle.GetComponent<Rigidbody>().MoveRotation(targetRotation);

granite oyster
#

You can also go full animation, and implement an animation blend tree. That would also probably fix it.

#

Its up to you.

signal fiber
granite oyster
#
            else
            {
                transform.Rotate(0, 180, 0);
            }

I don't expect you to get here to be honest. That's 1 specific pixel.

#

Rest of the code should somewhat work.

#

I would use RotateTowards instead so you have some smoothing, but that's just a nice to have.

azure needle
#

not changing

#

i could use rotate towards, but what would i point it towards tho?

granite oyster
#

Hmm strange, this code seems fine to me. Lets fix that first.

#

        else if(Input.GetMouseButton(0))
        {
            finalPos = Input.mousePosition;
            float diff = finalPos.x - initPos.x;
            Debug.Log(diff);
#

Put that Debug.Log there, @azure needle

azure needle
#

0

granite oyster
#

Debug.Log(diff + " " + finalPos.x + " " + initPos.x);

#

Put that there then

#

Something is wonky

signal fiber
granite oyster
#

If you click down, and hold, and then go left and right of that initial position

#

I was confused by the naming too

azure needle
granite oyster
#

Ohh.

#
    Vector3 initPos;
    Vector3 finalPos;

Make these float's, and change this finalPos = Input.mousePosition; to finalPos = Input.mousePosition.x; for all the things.

#

The reason for this is Reference Types and Value Types by the way...

azure needle
granite oyster
#
    int initPos = 0;
    [Header("Bike GO")]
    [SerializeField] private GameObject frontTyre;
    [SerializeField] private GameObject backTyre;
    [SerializeField] private GameObject handle;

    // Update is called once per frame
    void Update()
    {
        frontTyre.transform.Rotate(10f, 0, 0);
        backTyre.transform.Rotate(10f, 0, 0);
        changingAngle();
    }

    private void changingAngle()
    {
        if(Input.GetMouseButtonDown(0))
        {
            initPos = Input.mousePosition.x;
        }
        else if(Input.GetMouseButton(0))
        {
            int diff = Input.mousePosition.x - initPos.x;
            Debug.Log(diff + " " + finalPos.x  + " " + initPos.x);

            if(diff > 0)
            {
                transform.Rotate(0, 195, 0);
            }
            else if( diff < 0)
            {
                transform.Rotate(0, 165, 0);
            }
            else
            {
                transform.Rotate(0, 180, 0);
            }
        }
    }
#

Hmm that also won't work.

#

You need to cache the initPos

granite oyster
azure needle
#

and u havent set finalPos bro.

signal fiber
#

finalPos is not needed for this code pattern.

granite oyster
azure needle
#

initpos is a float

granite oyster
#

So?

azure needle
#

input.mouseposition.x - initpos?

granite oyster
#

Yeah that would get automatically converted afaik

#

Or make initpos an int

#

Also fine

#

You can make everything an int then

#

I changed it

azure needle
granite oyster
#

Funny how a different coding style can lead to problems with Reference Types and Value Types in the input system... Never had this problem before.

#

Every day is learning day it seems.

signal fiber
#

it's why I love engaging in discussion about peoples questions, it's a great way to learn and explore behaviors you probably wouldn't have encountered on your own ❀️

azure needle
#

rotating*

granite oyster
#

πŸ€”

signal fiber
#

there's also no dif value being printed there 🧐

granite oyster
#

Yeah he changed the log because I removed finalPos

#

So its probably dif initPos now

signal fiber
#

586 is a very large dif

granite oyster
granite oyster
#

You probably rotate something else then your model now then.

azure needle
granite oyster
azure needle
granite oyster
#

On what object does the script reside?

#

Where is your model in relation to that

azure needle
#

the bike.

#

the parent i mean

granite oyster
#

Show me

signal fiber
#

also just wondering but... isn't Input.GetMouseButton(0) and Input.GetMouseButtonDown(0) identical / the same condition, therefore the second if block never executes?

azure needle
granite oyster
#

Down is called 1 time, the time you actually clicked

#

The other one is called every time the mouse is down

azure needle
signal fiber
#

neat! that'll come in handy later πŸͺ couldn't hurt to check

granite oyster
azure needle
#

thats default

granite oyster
#

Once you actually run the game?

azure needle
#

forward is 180.

#

it was facing the camera, so i changed its rotation to 180

granite oyster
#

What I'm trying to ask: Run the game. Select the Bike. Does that rotation of the bike change?

azure needle
#

nope.

signal fiber
#

this may be a bit out there, but given rotations only happen while the mouse is down... what happens if you just put a transform.Rotate(0,90,0) at the top of Update() just to confirm rotations can occur?

granite oyster
# azure needle nope.

Can you show this in a screenshot to see if we actually talk about the same thing?

#

Also, remove your Animator

#

That is still doing the forward animation probably

azure needle
#

shit

#

it was because of the animator!

#

tf?

granite oyster
#

Finally...

#

What a series of events this was πŸ˜›

azure needle
granite oyster
#

I was wondering if that was going to happen πŸ˜›

azure needle
#

why the hell was animator blocking the rotation?

#

i wasnt even calling it in script

granite oyster
#

Animator has a position and rotation by default. You playing the animation sets the rotation and position, ignoring your script.

#

You also had an animation in there.

azure needle
#

ok. so it was playing the default animation till now.

#

which was to go forward always

granite oyster
#

transform.rotation = Quaternion.Euler(0, 195, 0);

#

that should work for the rotations

#

So you don't have the rotation disco

granite oyster
#

Anyhow, I gotta go back to work, otherwise boss man is going to be mad.

azure needle
#

when near end and not moving.

#

but yeah thanks @granite oyster and @signal fiber . Made my job a little easy. 🫑