#collision
1 messages · Page 1 of 1 (latest)
.
these sound like separate problems that should be tackled separately
a laser hitting the player doesn't really depend on direction: either we're getting zapped or we aren't
the wall jump one matters the most to be honest
let's focus on that, then
the thing is I want to know which parts of the body should be getting hurt
I feel like it's going to be very hard to meaningfully remember which side a collision came from, and to also correctly discard that information when the collision ends
(whether a player is fully covered by the laser or just his left hand)
hmm
If you have multiple places that can get hit by a laser, I'd just give each one its own hitbox
each one can then independent learn that it is or isn't being zapped
for the wall jump, I would do a physics query when you try to perform the jump
I guess I'd do an overlap-circle to check for a wall, and then an overlap-circle to check for anything that isn't a wall
or maybe an overlap-box
depends on the shape, I guess
it's going to be way harder to keep track of all of the collision events and to keep all of that straight
the thing is, if I try to make those 4 colliders not overlap it will either make the game feel weird or make the player have a weird overall collision shape
I would separate colliders used for movement from colliders used for hitboxes
The movement collider should be nice and smooth: no weird lumps to get caught on things
The hitboxes should be lumpier: better matched to your visuals
(and i'd use triggers for the things that can damage you)
a laser shouldn't be a thing you can collide with and stand on, probably!
i say this specifically because you're talking about taking damage on individual body parts
if that wasn't the case, then you could have a simple damage collider (or even re-use the movement collider, at that point)
That might work
those are options you weigh by testing the collision. either use separate hitboxes (what i've done myself), or get the direction based on the contact point and a center point to determine the direction (i've also done) . . .
but won't even more colliders overlaping make it have even weirder detections?
If damage is purely directional (and not a feature of specific parts of your hitbox), then I'd just measure the direction from the bullet to the player
maybe mix in the bullet velocity, too
I was thinking of a laser that is being charged, when it fires and you get in its way you get a lot of damage
what do you mean?
get a vector from the bullet to the player's center
I'd still say you should separate movement and hitboxes
That would avoid the issue entirely
I currently have the second option implemented, the only problem is I don't know any way of checking which side was a collision exited from
i don't currently see any reason to check which side a collision exited from, though :p
wall jumping is handled by just doing a few OverlapBox queries
and then compare the x and y of the bullet and the player to determine the side?
you'd just see which direction the vector points in, yeah
which is why you should be doing separate things for those two
you don't have to use a single collider for everything
it's the same way you determine which direction the collision entered, by checking the direction of the contact point or colliding object to a specific or center point of the object . . .
It literally doesn't work
is this healthy for the game? optimization-wise
premature optimization is evil
yes, tons of GameObjects can have and will have multiple colliders . . .
having a few colliders is fine
what and where (line of code) is this from?
one collider cannot always represent the shape of an object, so yes, you can use multiple . . .
which line does the error throw? no numbers in ss . . .
so I'd have a square collider covering the whole playre which would only collide with the terrain and then 4 colliders for determining where the attacks are coming from?
Right.
Different colliders for different duties.
you don't get a prize for using just one collider
I would raycast.
you can get the normal of the surface you hit
if that normal is mostly horizontal, allow a walljump
I don't have a clue about raycasting ðŸ˜
casting is sooo much easier for all this . . .
yeah, you definitely got XY problem'd, haha
Asking about your attempted solution rather than your actual problem
I really thought there is no other way since I tried doing it so many ways ðŸ˜
I will try raycasting and different colliders then, thanks
have you tried looging contactCount before accessing contacts?
if you get a hit, check the normal field of https://docs.unity3d.com/ScriptReference/RaycastHit2D.html
(also, make sure you're always using the Physics2D functions)
I'm pretty sure I tried that but it didn't work