public PhysicsObject(Rigidbody rigidbody, Collider[] colliders, PhysicsLayer layer) { Rigidbody = rigidbody; Colliders = colliders; PhysicsLayer = layer; GameObject = rigidbody.gameObject; }
public void init( NetworkPrefabLoader loader, GameData.TEAM team, EntityPlayer entity, Rigidbody rigidBody, Vector3 position, Vector3 to) { PhysicsLayer.SET_ATTACK(prefab, team); reader.enabled = true; reader.m_entity = entity; loadRocketModel.networkloader = loader; loadExplosionModel.networkloader = loader; loadRocketModel.team = team; loadExplosionModel.team = team; move.m_rigidBody = rigidBody; destroyNetworkObject.obj = entity.gameObject; destroyNetworkObject.isNetworkedObject = true; if (team == GameData.TEAM.RED) { loadExplosionPlayer.layer = PHYSICS_LAYER.LAYER_RED_ATTACK; } else { loadExplosionPlayer.layer = PHYSICS_LAYER.LAYER_BLUE_ATTACK; } this.transform.parent = entity.transform; this.transform.localPosition = Vector3.zero; this.transform.localRotation = Quaternion.identity; entity.transform.position = position; entity.transform.LookAt(to); }
public Projectile(Vector2 pos, Vector2 fwd, float _speed, PhysicsLayer mask) { Mesh projectileMesh = new Mesh(4, this, Color.Orange, PrimitiveType.LineLoop); projectileMesh.vertices[0] = new Vector2(-.3f, .2f); projectileMesh.vertices[1] = new Vector2(.3f, .2f); projectileMesh.vertices[2] = new Vector2(.3f, -.2f); projectileMesh.vertices[3] = new Vector2(-.3f, -.2f); meshes.Add(projectileMesh); position = pos; forward = fwd; Mask = mask; speed = _speed; killTime = Time.time + 3; if (Physics.PointMeshCollision(position, Mask)) { base.Destroy(); return; } Initialize(); }
void onCollision(Rigidbody body, EntityPlayer entity, Vector3 impactPoint) { if (m_state != GRENADE_STATE.TRAVELLING && m_state != GRENADE_STATE.BURNING) { return; } if (entity != null && (entity.m_team == GameData.TEAM.RED || entity.m_team == GameData.TEAM.BLUE)) { onDirectHit(entity); m_state = GRENADE_STATE.DEAD; return; } if (body.gameObject.layer == PhysicsLayer.GET_LAYER(PHYSICS_LAYER.LAYER_RED_SHIELD) || body.gameObject.layer == PhysicsLayer.GET_LAYER(PHYSICS_LAYER.LAYER_BLUE_SHIELD) ) { m_state = GRENADE_STATE.DEAD; return; } if (m_state == GRENADE_STATE.TRAVELLING) { m_state = GRENADE_STATE.BURNING; } m_triggerEnter.enabled = false; }
void hprDeployShieldAt(Vector3 position, Vector3 dirLook) { var shield = Instantiate(m_shield); shield.transform.position = position; shield.transform.LookAt(position + dirLook); PhysicsLayer.SET_SHIELD(shield, m_team); }
//circle public Collider(BaseObject p, Vector2 c, float rad, PhysicsLayer layer) { parent = p; center = c; radius = rad; Type = ColliderType.Circle; Layer = layer; }
//box public Collider(BaseObject p, Vector2 c, Vector2 ext, PhysicsLayer layer) { parent = p; center = c; extents = ext; Type = ColliderType.Box; Layer = layer; }
//mesh public Collider(BaseObject p, Mesh m, PhysicsLayer layer) { parent = p; center = Vector2.Zero; mesh = m; Type = ColliderType.Mesh; Layer = layer; }
public void RpcChangeHero(GameData.TYPE hero) { instantiateAvatar(m_entity.m_team, hero); if (m_entity == null) { return; } m_entity.m_type = hero; PhysicsLayer.SET_PLAYER(this.m_avatar, this.m_entity.m_team); }
public static Transform SPAWN(PREFAB_ID id, GameData.TEAM team) { switch (id) { case PREFAB_ID.MONK_PUNCH_SHIELD: var monkPunchShield = Instantiate <Prefab>(ME.PRF_MONK_PUNCH_SHIELD); PhysicsLayer.SET_SHIELD(monkPunchShield, team); monkPunchShield.gameObject.name = "MONK PUNCH SHIELD"; hprSetShieldColor(monkPunchShield, team); return(monkPunchShield.transform); case PREFAB_ID.MONK_PUNCH: var punch = Instantiate <Prefab>(ME.PRF_MONK_PUNCH); hprSetTeamColor(punch, team); return(punch.transform); case PREFAB_ID.ROCKET: var rocket = Instantiate <Prefab>(ME.PRF_ROCKET); hprSetTeamColor(rocket, team); return(rocket.transform); case PREFAB_ID.GRENADE: var grenade = Instantiate <Prefab>(ME.PRF_GRENADE); if (team == GameData.TEAM.RED) { grenade.setMaterial(ME.MAT_TEAM_RED); } else { grenade.setMaterial(ME.MAT_TEAM_BLUE); } return(grenade.transform); case PREFAB_ID.ROCKET_EXPLOSION: if (team == GameData.TEAM.RED) { return(Instantiate(ME.PRF_ROCKET_EXPLOSION_RED).transform); } return(Instantiate(ME.PRF_ROCKET_EXPLOSION_BLUE).transform); case PREFAB_ID.GREANDE_EXPLOSION: if (team == GameData.TEAM.RED) { return(Instantiate(ME.PRF_GRENADE_EXPLOSION_RED).transform); } return(Instantiate(ME.PRF_GRENADE_EXPLOSION_BLUE).transform); } return(null); }
public override bool init(EntityPlayer entity) { base.init(entity); var obj = GameObject.Instantiate <Prefab>(PREFAB); obj.transform.position = this.transform.position; obj.transform.rotation = this.transform.rotation; if (isParented) { obj.transform.parent = this.transform; } if (isPhysicLayer) { obj.setLayer(PhysicsLayer.GET_LAYER(layer)); } return(true); }
/// <summary> /// Register a physics object to the physics manager. /// </summary> /// <param name="colliders">All of the colliders on the given object</param> /// <param name="rigidbody"></param> public void Register(Collider[] colliders, Rigidbody rigidbody, PhysicsLayer type) { if (rigidbody == null) { Debug.LogError("Rigidbody can not be null"); } if (!_physicsObjects.ContainsKey(rigidbody.transform)) { _physicsObjects.Add(rigidbody.transform, new PhysicsObject(rigidbody, colliders, type)); } foreach (var collider in colliders) { RegisterChild(collider.gameObject, rigidbody.gameObject); } }
//public NEntity.NScript.EntityScriptReader reader; //public NEntity.NScript.LoadNetworkPrefab loadRocketModel; //public NEntity.NScript.MoveForward move; //public NEntity.NScript.LoadNetworkPrefab loadExplosionModel; //public NEntity.NScript.LoadPrefab loadExplosionPlayer; //public NEntity.NScript.GameObjectDestroy destroyNetworkObject; public void init( NetworkPrefabLoader loader, GameData.TEAM team, EntityPlayer entity, Rigidbody krigidBody, Vector3 position, Vector3 to) { PhysicsLayer.SET_ATTACK(m_prefab, team); m_team = team; m_networkloader = loader; m_networkloader.RpcLoadPrefab_ParentMe(PREFAB_ID.GRENADE, team); krigidBody.AddForce(entity.transform.rotation * m_initialForce, ForceMode.Impulse); //krigidBody.isKinematic = false; //m_explosion.gameObject.SetActive(false); m_entity = entity; m_rigidbody = krigidBody; //Debug.Log(m_rigidbody); m_networkloader = loader; m_triggerEnter.m_isRepeat = true; m_triggerEnter.resetCollisionCheck(); m_triggerEnter.addHdr(onCollision); m_prefab.setLayer(PhysicsLayer.GET_LAYER( (team == GameData.TEAM.RED) ? PHYSICS_LAYER.LAYER_RED_ATTACK : PHYSICS_LAYER.LAYER_BLUE_ATTACK)); }
public World(Game game, int seed, GameSave save) { Game = game; Map = new Map(this, game.MapType, seed, save.Level, save.Difficulty); var bounds = Map.Bounds; TerrainLayer = new TerrainLayer(bounds); ShroudLayer = new ShroudLayer(bounds); WallLayer = new WallLayer(bounds, ShroudLayer); PhysicsLayer = new PhysicsLayer(bounds); SmudgeLayer = new SmudgeLayer(); ActorLayer = new ActorLayer(bounds); WeaponLayer = new WeaponLayer(); ParticleLayer = new ParticleLayer(bounds); PathfinderLayer = new PathfinderLayer(bounds); WeatherManager = new WeatherManager(this, game.MapType); }
public static bool PointMeshCollision(Vector2 p, PhysicsLayer mask) { for (int i = 0; i < m_colliderList.Count; ++i) { //Is the collider in the cast mask if (m_colliderList[i].Layer == mask) { continue; } if (m_colliderList[i].Type != ColliderType.Mesh) { continue; } //Cannot fire a ray inside collider if (ExtensionMethods.MeshContainsPoint(m_colliderList[i].mesh, p)) { return(true); } } return(false); }
public void init(GameData.TEAM team) { PhysicsLayer.SET_ATTACK(m_prfAttack, team); PhysicsLayer.SET_SHIELD(m_prfShield, team); }
public PhysicsObject[] GetPhysicsObjectsWithLayer(PhysicsLayer physicsLayer) { return(_physicsObjects.Values.Where(physicsObject => physicsObject.PhysicsLayer == physicsLayer).ToArray()); }
public static bool RayCast(Vector2 c, Vector2 d, PhysicsLayer mask, ref RayCastHit hit) { if (m_colliderList == null || m_colliderList.Count <= 0) { return(false); } bool r = false; ContactPoint cp = new ContactPoint(); float d0 = float.PositiveInfinity; float d1; for (int i = 0; i < m_colliderList.Count; ++i) { //Is the collider in the cast mask if (m_colliderList[i].Layer == mask) { continue; } //Collider specific intersection methods switch (m_colliderList[i].Type) { case ColliderType.Mesh: if (!ExtensionMethods.MeshIntersection(m_colliderList[i].mesh, c, d, ref cp)) { continue; } //Contact point was inside the collider // if (Vector2.Dot(cp.point - ExtensionMethods.GetPolyCenter(m_colliderList[i].mesh.verticesWorldSpace), d) > 0) // continue; break; case ColliderType.Circle: if (!ExtensionMethods.CircleIntersection(m_colliderList[i].center, m_colliderList[i].radius, c, d, ref cp)) { continue; } break; default: return(false); } d1 = (c - cp.point).LengthSquared; //Current hit is further away than last if (d1 > d0) { continue; } hit.contact = cp; hit.other = m_colliderList[i]; r = true; } return(r); }
private void Awake() { ME = this; DontDestroyOnLoad(this.gameObject); }
public Tank(float acceleration0, float aimAcceleration0, float turnFactor0, Vector2 position0, Vector2 direction, Color color, InputScheme input0, PhysicsLayer layer) { List <Mesh> Meshes = new List <Mesh>(); //Hull Meshes.Add(new Mesh(new Vector2[4] { new Vector2(-2, 1), new Vector2(2, 1), new Vector2(2, -1), new Vector2(-2, -1) }, this, color, PrimitiveType.LineLoop)); //Forward Indicator Meshes.Add(new Mesh(new Vector2[2] { new Vector2(1.75f, 1), new Vector2(1.75f, -1) }, this, color, PrimitiveType.Lines)); //Tower Meshes.Add(new Mesh(new Vector2[4] { new Vector2(-.75f, .75f), new Vector2(.75f, .75f), new Vector2(.75f, -.75f), new Vector2(-.75f, -.75f) }, this, color, PrimitiveType.LineLoop)); //Cannon Meshes.Add(new Mesh(new Vector2[4] { new Vector2(.75f, .15f), new Vector2(3, .15f), new Vector2(3, -.15f), new Vector2(.75f, -.15f) }, this, color, PrimitiveType.LineLoop)); meshes = Meshes; forward = direction; position = position0; prevPos = position; acceleration = acceleration0; aimAcceleration = aimAcceleration0; turnFactor = turnFactor0; input = input0; for (int i = 0; i < meshes.Count; ++i) { meshes[i].forward = direction; } collider = new Collider(this, meshes[0], layer); Initialize(); }