Finding it annoying searching for this in the the documentation and in search engines as there's a lot of broken links, do you guys know what they replaced the syntax with for this code?
var namedObjectZ = namedObject.transform.basis.z
Finding it annoying searching for this in the the documentation and in search engines as there's a lot of broken links, do you guys know what they replaced the syntax with for this code?
var namedObjectZ = namedObject.transform.basis.z
It's the same. Might be good to check the documentation.
https://docs.godotengine.org/en/stable/classes/class_node3d.html
pickUpAreaCollider.apply_force(Vector3(0, 0, -20), Vector3(0, 5 * throwStrengthMultiplier, cameraBasisZ * throwStrengthMultiplier))
Interesting, that means I'm just applying the vector3 wrong then.
https://godotengine.org/qa/84642/what-does-invalid-call-nonexistent-vector2-constructor-mean
Oh, now I've just clicked on it, is it because the vector3 in apply force is a position rather than rotation which is what the transform.basis.z is returning? Or am I misunderstanding basis? I think the information helped me, I'm clearly adding force direction the wrong way. Presumably this means I need to use the transform.basis to the torque rather than the force.
Edit: Or hang on no, what I need to do is rotate the object being held to the Z appropriate axis first rather than applying the force in a direction.
Nope I'm getting lost, this is why I made the thread lol.
Force is to move the position. Torque is to rotate. In addition, you were putting in the parameters reversed.
Lethn basis.x, basis.y and basis.z are three vectors representing coordinate axes of some coordinate system, relative to its parent system. If you want to apply a force that's directed down the z axis and up the y axis of that coordinate system you'd do something like:
apply_force(whatever, basis.z * throwStrengthMultiplier + basis.y * throwStrengthMultiplier)
Or better yet transform your vector from basis space to parent space:
apply_force(whatever. basis * (.5, throwStrengthMultiplier, throwStrengthMultiplier))
In godot 3.x that would be:
apply_force(whatever, basis.xform(.5, throwStrengthMultiplier, throwStrengthMultiplier))
This is assuming that the basis is orthonormalized i.e. its coordinate system is not scaled or skewed, only rotated.
It was worse than that guys, I wasn't double checking what direction my transforms were facing so Z was returning 0 anyway ;( LOL. Been spending so much time on AI and interaction I forgot how to play with physics properly.
OKAY! This is more in line with what I had anyway because I wanted the force applied to be more tied into the click and hold movement so I used central impulse instead as it's a bit more friendly to the basis, bit of a code snippet for you to check out what I had in mind.,
if Input.is_action_pressed("RightClick") && hasPickedUpObject == true && canPickUpObject == false && miracleInUse == false && canThrowObject == true && hasPickedUpObject == true && isObjectThrowable == true:
var currentMousePosition = get_viewport().get_mouse_position().y
movementBasisZ = -movement.transform.basis.z
elif Input.is_action_just_released("RightClick") && canThrowObject == true && isObjectThrowable == true:
pickUpAreaCollider.apply_central_force(movementBasisZ * throwStrengthMultiplier)
pickUpAreaCollider.freeze = false
hasPickedUpObject = false
canPickUpObject = true
canThrowObject = false
isObjectThrowable = false
pickUpAreaCollider.collisionShape.disabled = false
pickedUpObjects.clear()
ShowGodHandIdle()
I don't know if I'll add Y force, I'll have a think, it's a throwing mechanic in case you were wondering lol, I'm just getting everything working at the moment and tweaking the behaviour. Of course ended up having to flip the maths to negative so it was facing the right direction when I was throwing the object.