How do i just use y position for cframe on roblox - roblox

I wanted to just use y position instead of the x,y,z positions. Here's my code

There's no way to just edit the Y-value alone, but you can append a new vector to your current vector, or recreate your vector with some of the old components.
Example:
local Position = Vector3.new(12, 5, 9)
local newPosition = Position + Vector3.new(0, 10, 0)
print(newPosition) -- prints (12, 15, 9)
The principle is the same for CFrames. You can also add a vector to a CFrame, if you just need clean movement on world axis.
local myCf = CFrame.new(12, 5, 9, ...) -- some CFrame, '...' corresponding to the CFrame-components for rotation.
local newCf = myCf + Vector3.new(0, 10, 0)
print(newCf) -- prints (12, 15, 9, ...)
Alternatively you can recreate your Vector/CFrame with existing components
local Position = Vector3.new(12, 5, 9)
local newPosition = Vector3.new(Position.X, 15, Position.Z)

Do you mean your wanting to get the y position of the object or only move it on the y property here are examples of both
ypos = part.Position.Y
or
part.CFrame = CFrame.new(part.CFrame.X,part.CFrame.Y,part.CFrame.Z)
for the second one leave everything the same but change the y value you can also move it from its current y value by leaving it all the same and on the part.CFrame.Y part of the code just add +1 or however much you want to move it by right after y hope this helps if not then im not understanding the question clearly

Related

SceneKit's look(at:up:localFront:) not working right in certain scenarios

This can be reproduced using the default Xcode 3D game template (SpaceShip).
Remove the runAction line that rotates the ship in the GameViewController.
Add this line. The ship correctly faces away from the camera.
Note the very small x component in the at: parameter.
ship.look(at: SCNVector3(0.001, 0, -100.0), up: SCNVector3(0, 1, 0), localFront: SCNVector3(0, 0, 1)) // Works! Ship faces away from camera.
However, it the x component of the at: parameter is exactly zero, the ship's orientation does not change. The ship continues to face the camera instead of facing away from it.
ship.look(at: SCNVector3(0, 0, -100.0), up: SCNVector3(0, 1, 0), localFront: SCNVector3(0, 0, 1)) // DOES NOT work
Seeing the same problem with simdLook()
For starters, if you show the world origin sceneView.debugOptions = ARSCNDebugOptions.showWorldOrigin], you will see that the x and y axis are actually opposite to what they would normally be, i.e. x is now y and y is now x.
Second, you are changing the x axis and not z axis. If you want the spaceship to look away or at you, that runs along the z axis. Negative(-) z will look at you where Positive(+)z will look away from you. Trying just changing the -100 to +100.

Right-to-left is messing up pixel positioning?

If I set up my html document as dir=rtl, all absolute positioned elements get moved to the right as expected but the translation is awkward. I need to move the elements to a negative position in order to center them correctly.
Removing the rtl solved the problem and everything retains the same Cartesian origin.
If you normally correct x to the center of the element like this:
x = x * windowWidth - elm.clientWidth / 2; // x is a value in [0..1]
Then you will probably need to do something like:
x = (x -1) * windowWidth + elm.clientWidth / 2;
If you want to position normally then don't divide by 2.

Convert From Local Coordinates To Global Coordinates

I've been writing a Parent/Child Entity system for a small game and I am having a problems when I try to get a child object's location.
As it stands now, the child of an Entity are transformed, rotated, and scaled in the coordinate space of the parent. This means that if our parent is at a location of ( 2, 3, 0 ) and we add a child to that parent at a location of ( 1, 2, 1 ), its world space is ( 3, 5, 1 ).
My problem is that I don't know how to convert from the local space ( 1, 2, 1 ), to the global space ( 3, 5, 1 ).
The obvious place to start is by adding the parent position and the child position. This works for non-rotated objects. Whenever rotation and scale are applied though it gets confusing and this is what I cannot figure out.
I read somewhere to use inverse of matrices but the explanation beyond that was not clear. Any help/mathematical insight/pseudocode would be greatly appreciated, thanks!
Just wanted to post this in case it helped anyone cause it caused me quite a bit of confusion.
This is actually very simple to do. All you have to do is multiply the parent entities model matrix by the child's model matrix then recover the coordinates from the bottom row like so.
In the example below we can see how I get the position from the model matrix of an entity with and without a parent. ( I do not actually do this. I store the position of each entity separately. This is just useful for entities that you know have a parent and need the position in the world space. )
Vector3f Entity::GetPosition() const {
Matrix4f matrix;
if ( GetParent() != 0 ) {
matrix = GetParent()->GetModelMatrix() * GetModelMatrix();
} else {
matrix = GetModelMatrix();
}
float x = matrix[ 3 ][ 0 ];
float y = matrix[ 3 ][ 1 ];
float z = matrix[ 3 ][ 2 ];
return Vector3f( x, y, z );
}
Note: I wrote my own matrix implementation so how you multiply and extract the positions will most likely be different.
The underlying concept used here is change in basis of matrix.
Using the axis vectors of the local coordinate system and coordinates with respect to the local coordinate system , the coordinates at global system can be obtained.
a = [a']M
a' - Coordinates wrt local axis
M - Basis matrix formed using vectors of axis
I found videos which explain the same in great detail .
Links :
1) https://youtu.be/zntNi3-ybfQ
2) https://youtu.be/1j5WnqwMdCk

Swift Scenekit - Multiple rotations

I have an issue with rotating an a node multiple times. I am working on a game with a rolling ball, and while I can rotate the ball along one axis, or two axis by the same amount, I cannot rotate at partial angles.
example:
// Roll right 90 -
SCNNode.pivot = SCNMatrix4MakeRotation(Float(M_PI_2), 0, 1, 0)
// Roll right 180 -
SCNNode.pivot = SCNMatrix4MakeRotation(Float(M_PI_2) * 2, 0, 1, 0)
// Roll up 90 -
SCNNode.pivot = SCNMatrix4MakeRotation(Float(M_PI_2), 1, 0, 0)
// Roll up & right 90 -
SCNNode.pivot = SCNMatrix4MakeRotation(Float(M_PI_2), 1, 1, 0)
All of which will work, however if I need to roll ball right 180 and up 90 I'm stuck.
Even if there was some way to add the vectors together that would do me.
Any help greatly appreciated.
To combine the effects of rotation matrices, use matrix multiplication.
To do that in SceneKit, you can either:
Create separate rotation matrices and multiply them together using SCNMatrix4Mult.
Apply a rotation directly to an existing matrix using SCNMatrix4Rotate. (This is equivalent to the SCNMatrix4MakeRotation + SCNMatrix4Mult option; it just combines those steps into a single function call.)
If the order of transformations is important to your app, remember that matrix multiplication order is the reverse of transformation order.

(MATLAB) How can I move the origin of plotted points?

I wasn't sure how to word this question so please link me to any answer if this has been asked before.
Let's say I have a graph with points making a line that starts at (5, 10) and goes to (10,10), but I want to move the points so that the first point starts at (0, 10) up to (5, 10). How do I go about doing this? Or what is this called so I can search on my own? I still want the points to be the same distances apart relative to each other but with one of the points at a specific location that I specify.
Simply take all of your points, and subtract or add them by a certain amount to move the origin. As such, because you want to move your line such that the horizontal component is shifted to the left by 5, you can just subtract every x co-ordinate by 5.
As such, assuming your co-ordinates are in x and y, just do:
final_x = x - 5;
final_y = y;
Then go ahead and plot these values:
plot(final_x, final_y);
In general, if you want to move your points by a prescribed amount, do this:
final_x = x + x_shift;
final_y = y + y_shift;
x_shift and y_shift would be the amount of movement you want the x and y co-ordinates to move. In this case, you want to move everything to the left by 5, and so x_shift = -5 and y_shift = 0. If you want to move everything such that the origin is located at (0,0), you would make x_shift and y_shift to be the minimum of the x and y values, or:
x_shift = min(x);
y_shift = min(y);
Using this will ensure that all of your points are with respect to (0,0).