Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LordViperion |
vel.x = (basis.z * input.y + basis.x * input.x).x
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LordViperion |
vel.x = (basis.z * input.y + basis.x * input.x).x
Reply From: | Bernard Cloutier |
They’re setting the x component of a velocity vector by mutliplying the y input (forward/backwards on a controller stick) with the forward vector (basis.z, although normally minus z is used as forward), and the x input (sideways motion on a controller stick) with the “sideways” vector, then only keeping the x component. Seems to me like basis.z * input.y is useless, since it will always result in an x of 0.
It would sure help to see the whole script though.
Thank you your answer. English is hard for me but i try.
(basis.z * input.y + basis.x * input.x).x
Interpreting the syntax of the code is a problem for me. I have never seen such a way to create a vector. Could you explain that this is because there is nothing about it in the documentation. Pls help.
Full code https://godottutorials.pro/fps-godot-tutorial/#Scripting_the_Player
but i only syntax is misunderstan for me only that one line what i writted my question. Vel.x = (x + y).x what is that syntax.
LordViperion | 2020-10-16 13:25
I think I see why you’re confused, and I can’t blame you.
basis
describes a 3d space and has 3 unit vectors. Those are confusingly named x, y and z. IMO they should have been named something like right
, up
and forward
, because each of those is a Vector3, not a float.
The input object looks like a Vector2. So it would look something like: { x: 1.0, y: -0.5 }
In this example, the user is pressing full right and half down on the joystick.
But the basis
object looks like this:
{
x: {
x: 1.0,
y: 0.0,
z: 0.0
},
y: {
x: 0.0,
y: 1.0,
z: 0.0
},
z: {
x: 0.0,
y: 0.0,
z: 1.0
}
}
Source: Basis — Godot Engine (stable) documentation in English
See what I mean when I say the naming of the unit vectors is confusing? To get the z
component of the forward vector you must write: basis.z.z
But the basis I shown is just the identity, meaning it’s equal to the “normal” axes. The basis is used also to represent rotation. So I was wrong when I said basis.z * input.y
is useless, since if the camera is rotated it won’t result in 0 all the time.
See these pages if you need a refresher on vectors and bases: Vector math — Godot Engine (stable) documentation in English
Matrices and transforms — Godot Engine (stable) documentation in English
Bernard Cloutier | 2020-10-16 14:27
OMG thank you I understand now you are the best!
LordViperion | 2020-10-16 18:28
I like this idea
Gallealonso | 2020-10-17 17:33
That’s how Unity does it. Instead of doing transform.basis.z
you just do transform.forward
where forward is like an alias for basis.z
.
Bernard Cloutier | 2020-10-17 22:01