Closed davids91 closed 1 year ago
I'm unlikely to implement this as most games that have a grappling hook have wildly different requirements for it, so I don't think it's particularly helpful to include as part of the library.
However, I have no objections to including a grappling hook example alongside the others, so if you want to create that example I'd be happy to merge it.
I'm unlikely to get around to doing it myself any time soon though.
I came up with this as an example, seems to work as expected, but am I missing anything?
let player_mass = 1.;
let spring = bevy_mod_wanderlust::Spring {
damping: 1.1,
strength: 0.5,
};
let elen = 0.; /* spring elongation */
let direction = (*anchor_position - *player_position).normalize(); //anchor is the other end of the spring
let distance = (*anchor_position - *player_position).length();
let displacement = distance - elen;
let magnitude = displacement * spring.strength;
let damping_force = -spring.damping * spring.damp_coefficient(player_mass);
let spring_force = (magnitude + damping_force) * direction;
player_impulse.impulse = spring_force;
I did not find the energy to work this into an example yet; And I was hoping for some confirmation before I do too.(And maybe some simplification/improvement suggestions should there be any ) Also this doesn't quite work as a grappling hook, as it provides upward forces as well, it's more like one of these, but in inverse: Fun!
I suppose that looks correct; I wouldn't really know without testing it myself. Feel free to implement whatever flavor of grapple hook- it'll match some games' needs and not others regardless.
The idea is that an Option can be given as an anchor point for the controlled character;
If it contains the struct, A spring-like force can be applied to the Character to correspond to the hook. https://github.com/PROMETHIA-27/bevy_mod_wanderlust/blob/4925e632b267d11ae377e438154a69cbe76f1886/src/spring.rs#L9
Handling could be similar to this : https://github.com/PROMETHIA-27/bevy_mod_wanderlust/blob/4925e632b267d11ae377e438154a69cbe76f1886/src/systems.rs#L144