#mystupidcode

1 messages · Page 1 of 1 (latest)

spiral sphinx
#

hi

#

here we go again i want to make one objects rotation on y axis same as other

quick cosmos
#

Well for axis inputs it's fine. But if you forget and put a button press in there it won't work most of the time.

spiral sphinx
#

oh ok

timber kindle
spiral sphinx
#

ok now to my question

spiral sphinx
#

how do i do that

#

just give me an example

timber kindle
#
float yRotation = OBJECTA.transform.eulerAngles.y; 
OBJECTB.transform.eulerAngles = new Vector3(OBJECTB.transform.eulerAngles.x, yRotation, OBJECTB.transform.eulerAngles.z );```
spiral sphinx
#

ok thanks will try it out

#

@timber kindle

#

i get errors

timber kindle
#

let that be a lesson not to just copy and paste things, i sent that as an example to look at and see what its doing.

spiral sphinx
spiral sphinx
timber kindle
spiral sphinx
#

wait a sec

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class wheelmovement : MonoBehaviour
{
    
 
public void Update()
 {
    GetInput(); 
 }
public void GetInput()
{
m_horizontalInput = Input.GetAxis("Horizontal");
m_verticalInput = Input.GetAxis("Vertical");

}
private void Steer()
{
m_steeringAngle = maxSteerAngle * m_horizontalInput;
frontDriverW.steerAngle = m_steeringAngle;

     float yRotation = m_steeringAngle.transform.eulerAngles.y; 
Steering.transform.eulerAngles = new Vector3(Steering.transform.eulerAngles.x, yRotation, Steering.transform.eulerAngles.z );


}


private void accelerate()
{
rearDriverW.motorTorque = m_verticalInput * motorForce;

}
private void UpdateWheelPoses()
{
UpdateWheelPose(frontDriverW, frontDriverT);

UpdateWheelPose(rearDriverW, rearDriverT);

}



private void UpdateWheelPose(WheelCollider _collider, Transform _transform)
{
Vector3 _pos = _transform.position;
Quaternion _quat = _transform.rotation;
_collider.GetWorldPose(out _pos, out _quat);
_transform.position = _pos;
_transform.rotation = _quat;
}
private void FixedUpdate()
{
    GetInput();
    Steer();
    accelerate();
    UpdateWheelPoses();


}

  private float m_horizontalInput;
 private float m_verticalInput;
 private float m_steeringAngle;
 public WheelCollider frontDriverW;
public WheelCollider rearDriverW;
public Transform frontDriverT;
public Transform rearDriverT;
public float maxSteerAngle = 30;
public float motorForce = 50;
public Transform Steering;

}

#

@timber kindle

spiral sphinx
#

hey do u have time to see my code

timber kindle
#

ur passing in the floats rather than the gameobejcts transform

#

m_steeringAngle is not a gameobject, how can it get its transform ?

spiral sphinx
#

well i need it to be float

timber kindle
#

that's why said not to copy without understanding what it does.

spiral sphinx
#

so that my other code works

#

first thing i did was that but

timber kindle
#

you asked how to set obja to rotation Y of objb

spiral sphinx
#

ok then if i made seperate script

#

which makes bars rot same as wheels

timber kindle
#

if u got m_steeringAngle already

spiral sphinx
#

would that work

spiral sphinx
timber kindle
#

it would prob then be cs Steering.transform.eulerAngles = new Vector3(Steering.transform.eulerAngles.x, m_steeringAngle, Steering.transform.eulerAngles.z ); ?

spiral sphinx
#

i will try

#

it works your amazing

#

i cant thank you enough

#

🙏

timber kindle
#

np. glad its working

spiral sphinx
#

now i just need to limit rotation of baars same way i did with wheels

#

i cant believe its almost finished

timber kindle
#

yes just a simple clamp

spiral sphinx
#

this is really stupid question but

#

this is my first time using clamp so

#

i will just watch a tutorial

#

i guess

timber kindle
#

close but you don't need +0

#

the first arguement is just the variable

#

no floats

#

also -0? lol wut

spiral sphinx
#

Ok I should just delete

#

+0

spiral sphinx
#

Will fix i

#

T

spiral sphinx
#

idk what to do

#

now

#

@timber kindle

#

figured it out

#

i dont need clamp

#

i have another problem

spiral sphinx
#

@timber kindle

#

hey so the code didnt work out

#

so i found anoother solution

#

i just made bars clild to front wheel

#

but now it rotates with wheels in x axis

timber kindle
#

wdym the code "ddint work out"

spiral sphinx
#

i tried limitimg rotation but

#

code worked until oi started driving

#

i will show u vid

#

Here

#

@timber kindle

timber kindle
#

the wheel turns ok?

spiral sphinx
#

Yes it didn't have any problem before too

timber kindle
#

just parent handle bars to wheels, looks like ur rotating both, differently

spiral sphinx
#

I tried that

#

Here

#

I tried limiting rotation

timber kindle
#

lol

spiral sphinx
#

I know

timber kindle
#

maybe constraints

spiral sphinx
#

They don't really work

#

I will show u how I use it

#

Maybe I am doing it wrong

timber kindle
#

show new code

#

ok

spiral sphinx
#

here

#

@timber kindle

timber kindle
#

what happens when u freeze y/z

#

i never used rotation constraint

spiral sphinx
#

doesnt do anything

#

damn

#

maybe i should write simple code that will keep rotation 0

#

i tried that but i did some stuff wrot

#

wrong

#

so maybe u know

timber kindle
#

where the new code that moved the handlebar

spiral sphinx
#

Hey sorry for not responding

#

I went to sleep

#

I think this should work better

#

I made handlebars child of a wheel

#

And if I just limit rotation on x axis it should work

#

@timber kindle

#

@slender skiff