#For me there is not enough info for this
1 messages Β· Page 1 of 1 (latest)
So the fact that it changes back is the jitter?
i suspect your jittering is coming from imperfect jittery movement by the physical mouse, what do you think?
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.
so mousebuttonup is the prob? π€
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?
not really.
That's the problem
Alright, lets change it around then.
How do you go back to the forward animation after clicking the mousebutton?
Very good
I just realized that i didnt assign movingleft to false when MouseButtonUp. FML π€¦ββοΈ
That's what I meant with:
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.
Another logical issue bro.
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?
What you are doing is checking from the last frame. So if you move 1 pixel right, you start the whole right sequence again.
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
ik. I was told to use anims on this server.
By whom?
I personally don't think that's valid advise to be honest.
Especially for a #π»βcode-beginner
I was doing this before i opted for anims.
Quaternion targetRotation = Quaternion.LookRotation(transform.position); handle.GetComponent<Rigidbody>().MoveRotation(targetRotation);
Yeah I would apply some smoothing for this, and actually look at where you are going, not transform.position. Then you wont have all this animation headache.
You can also go full animation, and implement an animation blend tree. That would also probably fix it.
Its up to you.
nope. not working.
https://gdl.space/irihipexuv.cs
not working how? a gif of the new code in action might be a good idea π
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.
well its just 180.
not changing
i could use rotate towards, but what would i point it towards tho?
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
0
Debug.Log(diff + " " + finalPos.x + " " + initPos.x);
Put that there then
Something is wonky
nah, the initPos is not being updated while mouse1 is down.
Which is the whole idea
If you click down, and hold, and then go left and right of that initial position
I was confused by the naming too
That makes no sense at all π
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...
same thing. diff is 0
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
Try that code I posted then.
same. not turning
and u havent set finalPos bro.
finalPos is not needed for this code pattern.
float diff = Input.mousePosition.x - initPos.x;
initpos is a float
So?
input.mouseposition.x - initpos?
Yeah that would get automatically converted afaik
Or make initpos an int
Also fine
You can make everything an int then
I changed it
π
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.
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 β€οΈ
its not turning tho.
rotating*
there's also no dif value being printed there π§
Yeah he changed the log because I removed finalPos
So its probably dif initPos now
586 is a very large dif
Like 25% of a 4k screen
Show your scene setup then.
You probably rotate something else then your model now then.
No what I mean is your Inspector
Show me
also just wondering but... isn't Input.GetMouseButton(0) and Input.GetMouseButtonDown(0) identical / the same condition, therefore the second if block never executes?
No
Down is called 1 time, the time you actually clicked
The other one is called every time the mouse is down
neat! that'll come in handy later πͺ couldn't hurt to check
Does that 180 degrees rotate there?
thats default
Once you actually run the game?
What I'm trying to ask: Run the game. Select the Bike. Does that rotation of the bike change?
nope.
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?
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
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.
ok. so it was playing the default animation till now.
which was to go forward always
transform.rotation = Quaternion.Euler(0, 195, 0);
that should work for the rotations
So you don't have the rotation disco
Yeah, that's why I always like that people show the full screen, so the helping people can see these kinds of things.
You don't know what you don't know, but some other people might know.
Anyhow, I gotta go back to work, otherwise boss man is going to be mad.