#How to add a texture on a mesh and rotate it correctly?
33 messages · Page 1 of 1 (latest)
How would you do this? Would you keep using the approach I'm doing of spawning a PbrBundle with a Rectangular mesh & a texture, then rotate it, or would you modify the texture of the object being hit somehow? (I don't know how to get there yet)
Code:
commands
.spawn(BulletHitMarker(Timer::new(Duration::from_secs_f32(10.0), TimerMode::Once)))
.insert(PbrBundle {
mesh: meshes.add(Rectangle::new(0.3, 0.3)),
transform: bullet_collision_event.at.with_translation(bullet_collision_event.at.translation + *bullet_collision_event.at.back() * 0.02).looking_at(bullet_collision_event.at.translation + *bullet_collision_event.at.forward(), *bullet_collision_event.at.up()),
material: materials.add(StandardMaterial {
base_color: Color::WHITE,
alpha_mode: AlphaMode::Blend,
base_color_texture: Some(game_assets.bullet_hole.clone_weak()),
perceptual_roughness: 0.8,
..Default::default()
}),
visibility: Visibility::Visible,
..Default::default()
})
.insert(Name::new("Bullet Hit Marker"));
What are you using to find the place where the bullet hits an object?
A raycast that gets the transform of the bullet when it collides with anything
yes but what do you use for the raycast?
what library
Rapier
it should provide a "normal" along with the position of the hit
I find that rapier barely gives you anything to work with...
Literally just gives me the entity and the time of impact
huh
Do you have any library that would make better raycasts, (if it can interact with rapier's colliders even better)
i use bevy_xpbd but thats an entire replacement for rapier
yeah rapier is a port of an existing physics engine while xpbd is made specifically for bevy
Yeah, I tried xpbd and liked it more, it just was missing some things and Rapier I had more experience with. Might have to rewrite to use xpbd
what missing things?
Can't remember now, it was a while ago and I could just not get what I wanted to do done, think it had to do with collisions & colliders. I do have to say xpbd was better overall
Btw found the method that gives me what i need using rapier
cast_ray_and_get_normal
ah cool
so basically the normal vector can be used to calculate the rotation of the decal
Yeah was going to ask, what would I multiply the normal with to find it?
you can use Quat::from_rotation_arc(Vec3::Z, ray.normal) to create a rotation from a normal vector
thank you so much, let me try it and I'll get back to you
@ebon fossil Amazing. Thank you so much! Works perfectly.
np
you need the normal raycast not just a ray cast
rapier_context.cast_ray_and_get_normal(ray_pos, ray_dir, max_toi, solid, filter)
i use it for my grappling hook
nvm see you found it
Thank you for taking the time!