Raycast not working
Options
in Photon Bolt
Hi . I would like to know why my raycast system isnt working with Bolt Entities, and how to make it work. Thank you
function Update () {
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, 30)){
Debug.DrawLine(transform.position, hit.point, Color.red);
Debug.Log ("Worked ");
}
}
function Update () {
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
var hit : RaycastHit;
if (Physics.Raycast(ray, hit, 30)){
Debug.DrawLine(transform.position, hit.point, Color.red);
Debug.Log ("Worked ");
}
}
0
Best Answers
-
yes it is included in the sample folder5
-
Look at WeaponRifle.cs for an example of this5
-
That error means you are trying to access a member of an array that doesn't exist. I would start with the tutorial code and make small changes at a time until you understand what is going on5
Answers
-
You need to use BoltNetwork.RaycastAll instead of Physics.Raycast0
-
And what things should I modify of the script above?Wizzard said:You need to use BoltNetwork.RaycastAll instead of Physics.Raycast
0 -
Look in the Bolt Tutorial for examples0
-
Which of them?stanchion said:Look in the Bolt Tutorial for examples
0 -
It is included with Bolt when you download it0
-
In here? (https://www.assetstore.unity3d.com/en/#!/content/41330). If so, how is it its file name?. If not, how can I get that tutorial?stanchion said:It is included with Bolt when you download it
0 -
yes it is included in the sample folder5
-
Please help0
-
And it got automatically answered. I didnt press anything O.o.0
-
It is in the package in the Sample folder0
-
Okay @stanchion. I made this 2 scripts in base of the tutorial you talked me about, but im getting this error: IndexOutOfRangeException: Array index is out of range.
BoltHitboxBodySnapshot.Raycast (Vector3 origin, Vector3 direction, .BoltPhysicsHits hits)
BoltPhysics.Raycast (Ray ray, .BoltHitboxWorldSnapshot sn)
BoltPhysics.Raycast (Ray ray, Int32 frame)
BoltNetwork.RaycastAll (Ray ray, Int32 frame)
CrosshairTest.OnOwner (.BoltEntity entity) (at Assets/CrosshairTest.cs:25)
CrosshairTest.Update () (at Assets/CrosshairTest.cs:7)
Script 01:
using UnityEngine;
using System.Collections;
public class WeaponBase : MonoBehaviour {
public byte damagePerBullet = 25;
public int refireRate = 5;
public int fireFrame;
public virtual void OnOwner(BoltEntity entity) {
}
public virtual void Fx(BoltEntity entity) {
}
}
Script 02:
using UnityEngine;
using System.Collections;
public class CrosshairTest : WeaponBase {
void Update (){
OnOwner (transform.parent.GetComponent());
}
public override void OnOwner(BoltEntity entity) {
if (entity.isOwner) {
Debug.DrawRay(transform.position, transform.rotation * Vector3.forward);
using (var hits = BoltNetwork.RaycastAll(new Ray(transform.position, transform.rotation * Vector3.forward), 60)) {
Debug.Log("2");
for (int i = 0; i < hits.count; ++i) {
Debug.Log(hits.count);
var hit = hits.GetHit(i);
var serializer = hit.body.GetComponent();
if ((serializer != null)) {
Debug.Log ("Hi ");
}
}
}
}
}
}
Can you please help me? Thank you0 -
Help please0
-
Look at WeaponRifle.cs for an example of this5
-
Yes, I've already done it. But I made some modifications and im getting the error I mentioned in the comment before.stanchion said:yes it is included in the sample folder
Thanks for your patience.0 -
That error means you are trying to access a member of an array that doesn't exist. I would start with the tutorial code and make small changes at a time until you understand what is going on5
-
Okay, thank you very much . I will keep this post up to date.stanchion said:That error means you are trying to access a member of an array that doesn't exist. I would start with the tutorial code and make small changes at a time until you understand what is going on
0 -
Do u get it to work ? I have the same problem, when i spawn a second entity with hitbox body and hitbox components on every bodypart i cant get andy information trought raycastall. when i shoot him the console say, hit.count is 0 every time is hit count 0. the entity has a character controller but i think its not the reason for my issue cause boltnetwork raycastAll i think only recognize boltnetwork hitboxes.
Heres the part from the script
sry that i bump and old thread but its the only thread that describe the same problem like me
{
Vector2 rnd = Random.insideUnitCircle * weaponStats.precision;
Ray ray = new Ray(weaponOrigin.position, _Camera.transform.forward + (_Camera.transform.up * rnd.y)+(_Camera.transform.right*rnd.x));
//Bolt Raycast
using (Bolt.LagCompensation.BoltPhysicsHits hits = BoltNetwork.RaycastAll(ray))
{
Debug.Log(hits.count);
for (int hitLayer = 0; hits.count > i; i++)
{
Debug.Log(hits.GetHit(i).body.ToString());
}
}
//Unity Raycast
RaycastHit hit;0 -
Ok i changed the part with raycastAll to
using (Bolt.LagCompensation.BoltPhysicsHits hits = BoltNetwork.RaycastAll(ray, BoltNetwork.Frame))
and now its count every hitbox in one round. And next test play its dont work anymore. one time its has worked i changed to boltnetwork.serverframe since then its not working now i changed back to boltnetwork Frame but nothing change. its really strange ...
I debugged it and when i shoot 100 shots to the entity its count 100 times 0 and one time 2, one time 3.
i hit only 5 time the hitbox from 100 shots0