Roblox Studio output error [Argument 1 missing or nil] - roblox

I want to make a sinking ship game in roblox. I got an error "Argument 1 missing or nil"
I want to make the ship rotate, but there is a problem in output.
Heres script:
wait(10)
X=script.Parent
for i= 8, 100 do
X:TranslateBy(script.Parent:SetPrimaryPartCFrame(script.Parent:GetPrimaryPartCFrame()*CFrame.Angles(-0.2, 0, 0.1)))
wait(5)
end
How can I rotate my ship?

You probably need to remove the X:TranslateBy() as translateby won't rotate your ship. (It takes in a vector)
As for the error, SetPrimaryPartCFrame does not return anything, which is why you are getting an error for TranslateBy

Related

Unity localScale problem with character stuck in wall

I recently downloaded unity, and I found that the localScale method was a better option for flip a character(especially for the box collider). But when I go close to a wall and turn, my character get stuck in wall. Do Code that I use](https://i.stack.imgur.com/zHuz1.png) have solutions ?Game preview](https://i.stack.imgur.com/C7vfj.png)
I tried to make my wall bouce my character and nothing changed, sometimes he got stuck.
It's easy to solve once you understand the 'base' by which the scale is flipped.
No. 1 and 2 of the uploaded image show the x scale value of 1 and -1 when the reference axis is in the center.
Numbers 3 and 4 are when the reference axis is moved to the (0, 0.5) position of the image center using the sprite editor, and the x scale value is set to 1, -1 in the same way.
I thank you for giving to me the solution to my problem.

How exactly is addforce impulse calculacted?

I'm having a bit of a problem that I have been trying to figure out for the last ~5 days, basically, I want an object to move by a specific amount using AddForce, for example, lets say 1 unit, however, when I use this snippet of code
body.AddForce(new Vector3(1,0,0), ForceMode.Impulse);
instead of moving it by 1 unit, so that the position is
1,0,0
It moves it by
0.03291207,0,0
so I realized that there is a calculation here, so I thought maybe for every 1 velocity, it moves it by 0.0329...., so I figured if I were to multiply the velocity by around 30, however, if I put
body.AddForce(new Vector3(30,0,0), ForceMode.Impulse);
, but now it moves it by
37.92695,0,0
, so I was really confused. So after making a spreadsheet and then copying and pasting different velocities and how they work, I finally figured it out. so it works a something a bit like this :
basically, there are 3 things, the input value [which we will call X], the velocity, and the position. the Velocity starts outs as the X, and every frame its decreased by - 0.2355
the position starts out as whatever position it is, and then there is a speed value, lets call it Y, now Y starts out as X divided by 100 and multiplied by 2, so for example if X is 1, Y would start out as 0.02, then, ~0.0048 is removed from Y, so now it's 0.0152, and then every frame, the position is increased by the Y value, and also every frame, Y is being decreased by ~0.0048, ~0.0048 being the friction [I think].
and now that I knew how it worked, I could reverse engineer, and I did! so I figured out that to get the object to move by 1 unit, I needed to input around 5.02 velocity. So, you might be wondering if I figured it out, why am I posting it here? well, the problem arises when I try to move it on the Z-axis at the same time, like
body.AddForce(new Vector3(1,0,1), ForceMode.Impulse);
now it moves it by on both axis by
0.0500636, 0, 0.0500636
instead of
0.03291207,0,0.03291207
. So this really made me confused, so then I made a spreadsheet and then copied and pasted different velocities and how they work. And it turns out the formula is still the same, however, 0.2355 and 0.0048 are changed, for example when it's
body.AddForce(new Vector3(1,0,1), ForceMode.Impulse);
, 0.0048 is actually 0.00332966 so Y is being decreased by 0.00332966 every frame, but if there are 2 different numbers, then, they both have different 0.0048's, for example, if it's
body.AddForce(new Vector3(1,0,2), ForceMode.Impulse);
. for 1 the value is 0.00210584 meaning Y gets decreased by 0.00210584 every frame, but for 2 in the same vector, 0.00421168 is the magic number, meaning Y is decreased by 0.00421168 every frame.
And that's where I'm stuck, I can't figure out where these numbers are coming from. I tried dividing it, multiplying it, subtracting and adding and I just cant figure it out. So I would really appreciate help from the physics experts here. Keep in mind that I don't know that much about physics and only know a bit about algebra and stuff like that, so I have no idea what the correlations are. If anyone needs it, here is the table I made showcasing every "magic number" from 1 to 6, the colored squares are squares that are quite similar
Sorry if this post was a bit confusing and sorry if I'm not supposed to ask this here, but I'm not sure where else on stack could i ask this, this whole topic is a bit confusing so I'm not sure if I explained it well enough, and I'm a bit tired, so if you didn't understand anything just leave a comment and I will try to answer it, Thanks in advance for any help :)

Unity returning incorrect transform.rotation

In the endless running game I am creating, there is a mechanic called the jump pad. It basically takes in the change in the player's position since the last frame and converts that to an angle. Then it uses that along with the transform.rotation of the jump pad to figure out which direction to move the player in, as if it was actually bouncing off of it.
This algorithm would've been working perfectly except for one problem: Unity was reading an incorrect transform.rotation. When the jump pad was rotated 45 degrees, it read 21.92615 (after being multiplied with Mathf.Rad2Deg.) When the jump pad was rotated 20 degrees, it read 9.949307.
At first I thought it was being multiplied by an unknown constant for some reason, but after checking it through the Calculator app I found this to be not exactly the case. After a bit more experimenting I found that the possible "unknown constants", while close enough together, did seem to have a range from around 2 to around 2.1. And while I don't have the faintest clue how this is happening, it does seem to be remarkably consistent.
So my question is: what is this problem I am facing and is there any way I can fix it? Brief side note: I know this is not some other problem with the code because I stripped it down to the bare minimum:
public void OnTriggerEnter2D(Collider2D collision){
Debug.Log(collision.gameObject.transform.rotation.z * Mathf.Rad2Deg);
}
OK. After looking up the scripting API for transform.rotation and messing around a bit, I discovered that it was returning the z value of a quaternion and fixed it using the .ToEulerAngles() call.

I can't get the right rotation of my transform in unity 3D

Hi everyone I have some little problem in Unity 3D. I am trying to do some walking simulation I have character and I have joints while she was walking I want to get the rotation of y. But when I try it I get some results like (transform of rotation in unity is -60 for example the value I get in program 0.059871 something like that how can I read the -60 the right value?)
Maybe you take the wrong properties, the Quaternion.y is a value from 0 to 1 (CMIIW)
but if you want to get you rotation in degree you can use Vector3.y by taking
var y = gameObject.transform.localEulerAngles.y;
Also, please attach your code before asking some code related issue

Compass: from 359 to 0 degrees

I am trying to move a robot using a compass. We use the compass to make the robot move in straight line, it uses 2 wheels and they move a bit different.
So we set a value between 0 and 359 as direction, and then check the current direction, calculate the error and fix it. Like error = current_direction - actual direction.
The problem is that if for example our init direction is 90 degrees and our robot is at 45, the error will be 45 and it will fix it. If it is 0, the error will be 90 and it will fix it. The problem is that if it moves a bit more than 0 and it goes for example to 359, the error will be -269 so instead of moving 90 in one direction it will move -269 in the other.
I use the sign of the error to decide which wheel to move to fix the direction.
any idea how to fix it?
if (error > 180) {
error -= 360;
}
if (error < -180) {
error += 360;
}
if your error is greater than 180°, you should rack it from 360 and invert the sign. Doing so, you can be sure your robot will always move in the shortest direction.
If your error is > than 180 degree simply switch your correction algorithm to calculate the correction by moving in the opposite direction. A simple if-else statement should do.
I don't know much about NXT and Mindstorm, but basically it is a common problem in circular motions. You could simply use two different coordinate systems and translate between each other, thats the most elegant way. Otherwise you could subtract 360 from your error, if the sign is negative, but that's a hack and not an elegant way to solve the problem ;-)