|
|
|
|
Reply From: |
Juxxec |
From the look_at documentation:
The target position cannot be the same as the node’s position, the up vector cannot be zero, and the direction from the node’s position to the target vector cannot be parallel to the up vector.
It is probably just that. While looking at the ground, the look at vector becomes parallel to the up vector. In that case there is no need to call the look_at function:
if aimcast.get_collision_normal().dot(Vector3.UP) > 0.001:
b.look_at(aimcast.get_collision_point() + aimcast.get_collision_normal(), Vector3.UP)
Hello!
Thanks for replying.
I tried what you said, and I thought it worked, but it still says the error.
I may have coded it wrong, so here’s the script (there’s more in the script but it’s not really important):
if aimcast.is_colliding():
var target = aimcast.get_collider()
if aimcast.get_collision_normal().dot(Vector3.UP) > 0.001:
var b = b_decal.instance()
aimcast.get_collider().add_child(b)
b.global_transform.origin = aimcast.get_collision_point()
b.look_at(aimcast.get_collision_point() + aimcast.get_collision_normal(), Vector3.UP)
Is there something wrong with the way I’ve added what you told me?
Redical | 2022-12-02 11:37
no this answer is totally correct you cant look_at
to from
where you want to look_at
and you’ll probably need to do a check to that effect
Wakatta | 2022-12-03 02:57
Right.
So - sorry I’m still new to Godot - what do you mean? Is there something I need to change to stop the error? Because also now I’ve changed a couple things and the bullet decal doesn’t show on flat walls, but it shows on everything else. I’ll be able to fix that I think, it’s just I think that might be affecting something now too.
It’s not important though, I’ll ask another question if that becomes a problem.
Redical | 2022-12-03 11:23
Juxxec already provided the example check
if aimcast.get_collision_normal().dot(Vector3.UP) > 0.001:
So you’re checking to make sure that the spacial isn’t at the location is trying to look at.
var direction = aimcast.get_collision_point() + aimcast.get_collision_normal()
if b.global_transform.origin != direction:
b.look_at(direction , Vector3.UP)
The flat surface error is most likely a depth issue with the decal. Do a simple test to verify.
Wakatta | 2022-12-03 13:16
Oh, I just got it to work!
I changed it to:
if aimcast.get_collision_normal().dot(Vector3.UP) > 0.0000000000000000000001:
… Then the code you’ve said before.
But, now I have yet another problem… So sorry about how difficult this has become…
Whenever I shoot at a surface that isn’t the floor while jumping, sometimes the bullet decal rotates incorrectly and is facing the same way it is in the bullet decal scene (Along -Z).
Here’s the code:
if aimcast.is_colliding():
var target = aimcast.get_collider()
var b = b_decal.instance()
target.add_child(b)
if aimcast.get_collision_normal().dot(Vector3.UP) > 0.0000000000000000000001:
b.global_transform.origin = aimcast.get_collision_point()
var direction = aimcast.get_collision_point() + aimcast.get_collision_normal()
if b.global_transform.origin != direction:
b.look_at(direction, Vector3.UP)
Thanks for any help. Again…
Redical | 2022-12-03 22:51