#Rotate the thingy
1 messages · Page 1 of 1 (latest)
What do you have?
a private float called targetAngle = 25;
Did you do this?
#💻┃code-beginner message
You replied "done."
Sorry I dont really have time or motivation to repeat everything
yess.
Show the code
1 sec hatebin buggy
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I think pastebin is good for this
It doesnt have highlighting, pretty hard to read :/
At least slightly better:
https://gdl.space/hazujesube.cs
So where are you updating targetangle..?
Hint: nowhere
As I said
Set your targetAngle to -25, 0 or 25 according to what keys you are holding. A, nothing or D
ye
I didnt say "Use transform.Rotate"
But when its private float it cant be updated, no?
It can. Private just means that it cant be accessed from other classes
targetangle is supposed to change. Its the steering wheel's non-smoothed rotation
We then use it as the target angle for our smoothed rotation
aha.
So did I made this right? I dont think so
if (Input.GetKeyDown(KeyCode.A))
{
targetangle -= 25;
}
That's not setting a value, that is subtracting from a value
oh
Tbh you should just use GetAxisRaw("Horizontal") to get your A-D input as a float afrom -1 to 1
Put that in a variable, lets say horizontalInput
Then you can just say targetAngle = horizontalInput * 25f
but I have an InputManager script
or something like that
private void FixedUpdate()
{
// pass the input to the car!
float h = CrossPlatformInputManager.GetAxis("Horizontal");
float v = CrossPlatformInputManager.GetAxis("Vertical");
No idea what CrossPlatformInputManager is but use that instead of Input, if it works.
And if theres a reason to
crossplatformInputManager is like input but for mobile too.
i think
Uhm, so error code "cannot convert type float to bool"
It would be easier to help if i didnt have to keep asking for your current code
Just the lines you changed is enough
Especially the error line
Yeah dont put the GetAxisRaw in an if statement, it returns a float
Just this^
Replace horizontalInput with the ..GetAxisRaw(...) or make it a separate variable
Okey. And how can I assign the gameobject to this?
I dont know what you mean by that
How is your steering wheel rotated, can you show that
In the scene view with the object selected with local gizmos
But theres the problem, it is not rotating
because the steering wheel is not assigned to the codeline
i think
Yeah we arent there yet
What is the steering wheel's axis that it should rotate around?
It should rotate on the Y axis
Does your script have a reference to the steering wheel object?
yess.
Its not in english mostly so im not sure
yeah, its in Hungarian
Okay which object is that
Alright. Try setting its transform.localRotation to Quaternion.Euler(0, targetAngle, 0) for now
It wont be smoothed yet but you can see if the target rotation is correct
Nah just add this linecs Kkormany.transform.localRotation = Quaternion.Euler(0, targetAngle, 0);
Quaternion.Euler creates a rotation with those angles. You only want Y so you leave the X and Z angles to zero.
Nice. Okay now you can apply the smoothing to a second variable. Make a new private float, you can call it smoothedAngle or something. Now you can choose from a few ways of smoothing: MoveTowardsAngle, LerpAngle or SmoothDampAngle are functions in the Mathf class, you can choose one or try all and see whats best for you
-MoveTowards will change the at a constant speed
-Lerp will change the value quicker depending on how far it is from the target value.
-SmoothDamp has smoothing at the start and end, but its a bit more complicated to use (extra ref variable)
Okkey. So I think the MoveTowards will the best for this.
So I need to make a second variable.
targetangle = Input.GetAxisRaw("Horizontal") * 25f;
just like this?
but with Mathf?
noo. I just realised thats not how to do that
so a second variable
See the example in the doc:
https://docs.unity3d.com/ScriptReference/Mathf.MoveTowardsAngle.html
Use the targetAngle as the target value
And smoothedAngle as the current value
smoothedAngle = Mathf.MoveTowardsAngle(smoothedAngle, targetAngle...)
So you kind of update the smoothed angle from itself towards the target angle every frame
So is it correct?
smoothedAngle = Mathf.MoveTowardsAngle(smoothedAngle, targetangle, speed);
Yep, but you want to multiply speed with deltaTime if you didnt already. This is so that its the same speed no matter your FPS
so speed * Time.deltaTime?
So now it looks like
smoothedAngle = Mathf.MoveTowardsAngle(smoothedAngle, targetangle, speed * Time.deltaTime);
targetangle = Input.GetAxisRaw("Horizontal") * 25f;
Kkormany.transform.localRotation = Quaternion.Euler(0, smoothedAngle, 0);
Update the target angle before the smoothed angle. Other than that it looks ok
Nice 👍 No problem