near sensor doesn't work when teleported inside object.

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.

what does that mean, “deprecated”?

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. :slight_smile:

We could really use ‘Localize’ as a command,

I use

            Diff = Ray[0].worldPosition-Ray[1]
            Diff = Ray[0].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?

Collision works with Static(ghost) fine. I use it all the time for area triggers.

I’ll give that a try then.

I frequently use a sensor object and collision.hitObjectList for explosions etc.

I created a very simple example of the problem I have.

blender file

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.

Collision sensors won’t detect collisions between two static objects. At least one of the objects must be set to Dynamic or Rigid Body.

For the Near sensor, objects need to have Actor enabled to be detected.

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.

new Blender file

are you checking .hitObjectList? or .hitObject?

is it hitting more than 1?

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.

yay, you found the problem. instead of using true level triggering, could I set the sensor to false with python before I teleport it?

You can also enable the Pulse mode on the collision sensor, which will trigger the controller whenever the collision set (objects that are tracked by the collision sensor) changes.

just enabling pulse mode didn’t work. is there a way to set the sensor to false or reset it?

It looks like Pulse Mode only generates a pulse when the length of the hitObjectList changes instead of when any object in the list changes. This may be a bug.

You cannot set the state of a sensor as it is a read-only attribute. Even if you could, you would need a running Python script to do so. For now, just use True Level Triggering.