Sorting Through Bolt RaycastAll

BoltUser
BoltUser
edited December 2016 in Photon Bolt
Hi everyone, I've read a lot of different posts over the last few months but I've posted nothing myself. I've got a lot of help just reading here and other places but I've ran into some trouble here. I will post 5 pictures to help see what I'm working with. I've tried a lot of things, this is the closest I've gotten so far, I've tried many other ways that I can share too.

After the pictures, I will explain more below.











For some reason, once there is more than one serializer, the Player’s information is automatically bumped to the last element of the hits array, no matter the shot order. I try to take advantage of that with my whereRayHitboxesCenter [hits.count-1] < whereRayHitboxesCenter [0]. I check to see if the last element (the player) is closer than the first element in the array (a wall or something to take the bullet hit).

I thought about layer masks but each floor and wall piece is a bolt entity and what I want is for each one to be able to be destroyed. Each wall and floor will have it’s own health. I need to know the hit order.

What I want with this Bolt raycastall:

If I shoot a wall, then I want it to take 100 percent damage, the 2nd layer 50 percent, the 3rd 25 percent, and if there is player in front of those walls, hit the player and not the buildings. If there is a player behind those walls, don’t damage the player. I can take care of the different damages but not if I don't have a reliable way of knowing who was hit first.

Any help will be much appreciated, I can provide more information. Below is the weapons script file from the Tutorial that has been so helpful:

using UnityEngine;
using System.Collections;
using Bolt;

public class WeaponRifle : WeaponBase {
public override void OnOwner(PlayerCommand cmd, BoltEntity entity) {
if (entity.isOwner) {

IPlayerState state = entity.GetState();
PlayerController controller = entity.GetComponent();

Vector3 pos;
Quaternion look;

// this calculate the looking angle for this specific entity
PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, state.pitch, out pos, out look);

// display debug
Debug.DrawRay(pos, look * Vector3.forward);

using (var hits = BoltNetwork.RaycastAll(new Ray(pos, look * Vector3.forward), cmd.ServerFrame)) {


float[] whereRayHitboxesCenter = new float[hits.count];
for (int i = 0; i < (hits.count); ++i) {

//Serializers

//Player
var hit = hits.GetHit (i);
var serializer = hit.body.GetComponent ();

//Buildings
var hith_wall = hits.GetHit (i);
var hitv_wall = hits.GetHit (i);
var hitfloor = hits.GetHit (i);

var h_Wallserializer = hitv_wall.body.GetComponent ();
var v_Wallserializer = hith_wall.body.GetComponent ();
var floorserializer = hitfloor.body.GetComponent ();

if (serializer != null)
{
float dist = Vector3.Distance(pos, serializer.transform.position);
whereRayHitboxesCenter[i] = dist;
BoltLog.Error (serializer.state.name + " hit! " + " [i] is: " + i + "! Vector3.Distance(pos, serializer.transform.position!" + dist + " and hit.distance is " + hit.distance + "!");

if (i < 1)
{
serializer.ApplyDamage (controller.activeWeapon.damagePerBullet);

}

if (whereRayHitboxesCenter[hits.count-1]" +whereRayHitboxesCenter[0]);

}
}
if (h_Wallserializer != null)
{
float dist = Vector3.Distance(pos, h_Wallserializer.transform.position);
whereRayHitboxesCenter[i] = dist;
BoltLog.Error (h_Wallserializer.state.name + " hit! " + " [i] is: " + i + "! Vector3.Distance(pos, h_Wallserializer.transform.position!" + dist + " and hith_wall.distance is " + hith_wall.distance + "!");
}

if (v_Wallserializer != null)
{
float dist = Vector3.Distance(pos, v_Wallserializer.transform.position);
whereRayHitboxesCenter[i] = dist;
BoltLog.Error (v_Wallserializer.state.name + " hit! " + " [i] is: " + i + "! Vector3.Distance(pos, v_Wallserializer.transform.position!" + dist + " and hitv_wall.distance is " + hitv_wall.distance + "!");
}

if (floorserializer != null)
{
float dist = Vector3.Distance(pos, floorserializer.transform.position);
whereRayHitboxesCenter[i] = dist;
BoltLog.Error (floorserializer.state.name + " hit! " + " [i] is: " + i + "! Vector3.Distance(pos, floorserializer.transform.position!" + dist + " and hitfloor.distance is " + hitfloor.distance + "!");
}
//end of loop
}
}
}
}

public override void Fx(BoltEntity entity) {
Vector3 pos;
Quaternion rot;
PlayerCamera.instance.CalculateCameraAimTransform(entity.transform, entity.GetState().pitch, out pos, out rot);

Ray r = new Ray(pos, rot * Vector3.forward);
RaycastHit rh;

if (Physics.Raycast(r, out rh) && impactPrefab) {
var en = rh.transform.GetComponent();
var hit = GameObject.Instantiate(impactPrefab, rh.point, Quaternion.LookRotation(rh.normal)) as GameObject;

if (en) {
hit.GetComponent().enabled = false;
}

if (trailPrefab) {
var trailGo = GameObject.Instantiate(trailPrefab, muzzleFlash.position, Quaternion.identity) as GameObject;
var trail = trailGo.GetComponent();

trail.SetPosition(0, muzzleFlash.position);
trail.SetPosition(1, rh.point);
}
}

GameObject go = (GameObject)GameObject.Instantiate(shellPrefab, shellEjector.position, shellEjector.rotation);
go.GetComponent().AddRelativeForce(0, 0, 2, ForceMode.VelocityChange);
go.GetComponent().AddTorque(new Vector3(Random.Range(-32f, +32f), Random.Range(-32f, +32f), Random.Range(-32f, +32f)), ForceMode.VelocityChange);

// show flash
muzzleFlash.gameObject.SetActive(true);
}
}


**
PS in the 4th picture it's 3 shots, not 4, I'm tired and putting all this together was rough. Alt-Tab is my friend.

Comments

  • BoltUser
    BoltUser
    edited December 2016
    Below helps me understand why raycastall is not in a certain order.


  • In the end I ended up firing 2 rays.

    Physics.RaycastAll doesn't guarantee order so I sorted the results.

    1 ray was for unity collisions so I could order the distance.

    The other ray was the Bolt one.
  • I was trying to compare Bolt's raycast to Unity's to see if we hit a collider before we hit Bolt's hitbox.

    Did you notice that the Bolt Raycast and the Unity Raycast measure different distances?
    For me, Bolt's is about 1/2 the distance than that of Unity's. Not sure what is going on.
  • No, I don't have that problem.

    Screenshots and moar details.