#How to add a texture on a mesh and rotate it correctly?

33 messages · Page 1 of 1 (latest)

naive mulch
#

I've implemented a bullet hole decal system, it rotates to look in the direction the bullet came from, so when firing at a perpendicular surface, it works amazing.
But when fired at a surface that intersects at a non-perpendicular angle it looks bad

#

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"));
ebon fossil
naive mulch
ebon fossil
#

what library

naive mulch
#

Rapier

ebon fossil
#

it should provide a "normal" along with the position of the hit

naive mulch
#

I find that rapier barely gives you anything to work with...

naive mulch
ebon fossil
#

huh

naive mulch
#

Do you have any library that would make better raycasts, (if it can interact with rapier's colliders even better)

ebon fossil
#

i use bevy_xpbd but thats an entire replacement for rapier

naive mulch
#

Yeah, that's the thing

#

I'm really growing tired of rapier... Thanks for the help

ebon fossil
#

yeah rapier is a port of an existing physics engine while xpbd is made specifically for bevy

naive mulch
ebon fossil
#

what missing things?

naive mulch
#

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

ebon fossil
#

ah cool

#

so basically the normal vector can be used to calculate the rotation of the decal

naive mulch
#

Yeah was going to ask, what would I multiply the normal with to find it?

ebon fossil
#

you can use Quat::from_rotation_arc(Vec3::Z, ray.normal) to create a rotation from a normal vector

naive mulch
#

thank you so much, let me try it and I'll get back to you

ebon fossil
#

np

merry siren
#

i use it for my grappling hook

#

nvm see you found it

naive mulch