Solved Raycasting from an entity?

Jakkee

Retired Staff
Retired Staff
Plugin Developer
Jul 28, 2014
1,465
933
113
Australia
I am trying to raycast from an entity into the sky, This is what I have and it keeps returning turn weather or not its under something.
Python:
class RockBaseFinder:
    def On_EntityDeployed(self, Player, Entity):
        if Player.Admin:
            origin = Util.CreateVector(Entity.X, Entity.Y, Entity.Z)
            #^^Testing on 1.0.7B not 1.0.8^^
            direction = Util.CreateVector(float(0), float(1), float(0))
            hit = UnityEngine.Physics.Raycast(origin, direction)
            if hit:
                #Player.Message("Hit something, A rock?")
            else:
                Player.Message("Nothing above")
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,095
4,815
113
At your house.
github.com
I am trying to raycast from an entity into the sky, This is what I have and it keeps returning turn weather or not its under something.
Python:
class RockBaseFinder:
    def On_EntityDeployed(self, Player, Entity):
        if Player.Admin:
            origin = Util.CreateVector(Entity.X, Entity.Y, Entity.Z)
            #^^Testing on 1.0.7B not 1.0.8^^
            direction = Util.CreateVector(float(0), float(1), float(0))
            hit = UnityEngine.Physics.Raycast(origin, direction)
            if hit:
                #Player.Message("Hit something, A rock?")
            else:
                Player.Message("Nothing above")
Lemme summon @Snake here. He can tell you more, and If there is something, I can convert It to Py for you.
 
  • Like
Reactions: Snake

Snake

Moderator
Moderator
Jul 13, 2014
288
174
28
Mmmmm, use RaycastAll to get all the colliders. Why ? Because you'll hit the entity itself and that will be useless. For example, if you raycast from a wall position you'll probably hit the wall collider and so it will allways give true;

C#:
RaycastHit[] hits = UnityEngine.Physics.RaycastAll(origin, direction, distance);

Collider entityCollider = entity.GetTakeDamage().gameObject.GetComponent<BoxCollider>();

foreach (RaycastHit hit in hits)
{
     if (!hit.collider.Equals(entityCollider)){
          Server.GetServer().Broadcast("There's something over the entity!");
     }
}
On each hit it checks if the hit.collider equals the entity collider


I'm not sure if "entity.GetTakeDamage().gameObject.GetComponent<BoxCollider>();" works, I've never tried it, but it should.
 
  • Informative
Reactions: Jakkee