when I use something like “own.position” to teleport the player(a sphere) to a point inside a cube, the near sensor does not detect that the player is inside the cube. I have to move the player out of the cube and back in for the near sensor to detect the cube.
how can I fix this?
some context: I am using a near sensor to detect when the player enters an area, i.e., a cube. I use these areas to determine where the player should respawn. in every instance, the point to which the player respawns is within said area.
There isn’t anything about your description that shouldn’t work, but there are a lot of things that you could get wrong while implementing it. You should post a simple .blend file showing your setup so we can see any mistakes you might have made.
A couple side notes:
-You shouldn’t use the KX_GameObject “position” attribute since it is deprecated. Use “worldPosition” or “localPosition” instead.
-While a near sensor should work for what you’ve described, you should probably be using a collision sensor instead as they are more efficient.
Isn’t the near sensor essentially just a sphere collision box?
I always wanted clarification on that… so if I see it correctly, this “sphere” then would have to actually collide with a face in this big box you’re moving the player into. Also check if your distance is right on the near sensor and make sure it goes below player’s feet.
But yeah in your case it sounds like you would be better off just using collision.
I assumed collision doesn’t work when passing through an object. I’m using the “static” physics type with ghost checked for the cubes that the player passes through and gets teleported to. should I use something else?
When something is deprecated it means that it has either been replaced by a superior alternative or been renamed. In this case it has been replaced by the worldPosition (states where object is in the world) attribute to make room for the newer localPosition attribute (states where an object is in correspondance to its parent). Just replace position with worldPosition.
Diff = Ray.worldPosition-Ray
Diff = Ray.worldOrientation.inverted()*Diff
## this will be used to then check to see if this type of part
## can go at this location and that the jack in unoccupied and
## that the unit the part is hooking to is friendly
after a point is localized its easy to use diff.x and diff.y and diff.z to limit angles and all sorts of things.
if they are in front and within x rang cast a ray at them, do you see them?
use the number keys 1-4 to teleport the “player”(the isosphere) to four different points. the collision sensor on the isosphere never detects any collisions even when the sphere intersects the last object. this doesn’t work for a near sensor either.
I tried it with rigid bodies, and now the first cube gets detected but not the others. I added a line of code to output the property to the console every time there is a collision. make sure to check the console.
Controllers will only be evaluated if a sensor attached to it is triggered. By default, sensors are only triggered when their state changes. In your case, the collision sensor is only triggered when it initially collides with something, or initially stops colliding.
Since you immediately move the player from one cube to another, there is no frame where the collision sensor stops colliding. Thus its state never goes from True to False, and your Python controller is not triggered. If you want to be able to handle this situation, you should enable True level triggering on the collision sensor. You can prevent your script from running code unnecessarily using if statements to check the state of the sensor, what object is being collided with, etc.