Single Entity Constraint and Custom Raycasts
Posted: Mon Nov 08, 2010 8:45 pm
So... I've got 2 questions.
The first: I have a spherical detector volume at the end of my level, when I hit that volume, I want my player (also a sphere) to be tethered to the middle of that volume. Since the volume isn't an entity, I can't do a normal entity-entity DistanceLimit. How difficult would it be to write a SingleEntityConstraint to act as a Entity<->Point max distance constraint? Barring that, I could obviously stick a Kinematic entity in the middle, but then the player would collide with that, so if I went that route, how would I keep the player from colliding with the proxy entity.
The second question: I've mostly finished porting my game over from JigLibX, but one of my last issues is a raycasting problem. I was shooting a ray from my player towards the camera, and dropping the camera in front of anything the camera collided with. JigLibX allowed me to pass a delegate into the raycast so I could ignore the player object. In BEPU I'm having problems with the raycast detecting the player, and dropping the camera inside him. The player is a sphere primitive, so I tried reducing the ray's length to camera distance - radius (and event toyed around with max radius, margins, and an arbitrary padding) and in some cases, such as the ball rolling towards the camera, I would still "catch" the ball in the ray. Is there anyway to ignore the ball while raycasting?
I also tried using the hitEntities raycast, and hitLocations had 3 entries (player sphere, and 2 wall trianglemeshes), but hitEntities had 1 valid entry (player sphere) and dozens of null entries. So I couldn't ignore the player object that way, unless I tested every hit location to see which object it lived in, which seems like a huge performance hit.
Currently I'm using the single hitEntity raycast, and ignoring it if the player is the entity. This isn't perfect however, in that if the player is touching a wall and the camera is between them, it has the potential to detect the player and use the "i'm not colliding with anything" logic.
The first: I have a spherical detector volume at the end of my level, when I hit that volume, I want my player (also a sphere) to be tethered to the middle of that volume. Since the volume isn't an entity, I can't do a normal entity-entity DistanceLimit. How difficult would it be to write a SingleEntityConstraint to act as a Entity<->Point max distance constraint? Barring that, I could obviously stick a Kinematic entity in the middle, but then the player would collide with that, so if I went that route, how would I keep the player from colliding with the proxy entity.
The second question: I've mostly finished porting my game over from JigLibX, but one of my last issues is a raycasting problem. I was shooting a ray from my player towards the camera, and dropping the camera in front of anything the camera collided with. JigLibX allowed me to pass a delegate into the raycast so I could ignore the player object. In BEPU I'm having problems with the raycast detecting the player, and dropping the camera inside him. The player is a sphere primitive, so I tried reducing the ray's length to camera distance - radius (and event toyed around with max radius, margins, and an arbitrary padding) and in some cases, such as the ball rolling towards the camera, I would still "catch" the ball in the ray. Is there anyway to ignore the ball while raycasting?
I also tried using the hitEntities raycast, and hitLocations had 3 entries (player sphere, and 2 wall trianglemeshes), but hitEntities had 1 valid entry (player sphere) and dozens of null entries. So I couldn't ignore the player object that way, unless I tested every hit location to see which object it lived in, which seems like a huge performance hit.
Currently I'm using the single hitEntity raycast, and ignoring it if the player is the entity. This isn't perfect however, in that if the player is touching a wall and the camera is between them, it has the potential to detect the player and use the "i'm not colliding with anything" logic.