SimulateOwner and mouse click detection

Options
Aslan85
Aslan85
edited November 2015 in Photon Bolt
Hi,

I have another question about bolt.

In a player class :
public class PlayerBehaviour : Bolt.EntityEventListener {}

I have the method :
public override void SimulateOwner() {}

With a shoot function inside it :
if(Input.GetMouseButtonDown(0) && !isShooting) {
isShooting = true;
motor.Shoot(transform.position, transform.up); // Method to call the raycast
UnityEngine.Debug.Log("Number Shoot");
}
if(Input.GetMouseButtonUp(0))
isShooting = false;

When I click one time, the "Number Shoot" log is calling 3 times.
Do you know why ?

I try to fix it with an authoritative server and the executeCommand that allow a "BoltCommand.isFirstExecution" but I had encountered a problem that I hadn't fix to the moment.

If you have any ideas. Please, inform me.

Thank you !

PS : I'm using Unity 5.2.2f1 and Bolt Beta-v0.4.3.8

Comments

  • Aslan85
    Aslan85
    edited November 2015
    Options
    OK, I continue with this ticket.

    First, I set an authoritative server. With problem, sure, but I resolved here : http://forum.photonengine.com/discussion/6859/problem-with-executecommand

    Second, when I set the server, I used the script created by "ddd" here : http://forum.photonengine.com/discussion/6869/simulatecontroller-and-executecommand-example I was a certain misunderstand between "SimulateController" and "SimulateOwner".

    I was thinking that with an authoritative server and boolean "IsFirstExecution" of Bolt.Command, that's resolve the click problem but it didn't.
    I send a part of the code :
    void PollKeys(bool mouse){
        _horizontal = Input.GetAxis("Horizontal");
        _vertical = Input.GetAxis("Vertical");
        if (mouse) {
            _leftClickDown = Input.GetMouseButtonDown(0);
            _leftClickUp = Input.GetMouseButtonUp(0);
        }
    }
    
    void Update() {
        PollKeys(true);
    }
    
    public override void SimulateController() {		
        PollKeys(false);
        IPlayerCommandInput input = PlayerCommand.Create();
        input.Horizontal = _horizontal;
        input.Vertical = _vertical;
        input.LeftClickDown = _leftClickDown;
        input.LeftClickUp = _leftClickUp;
        entity.QueueInput(input);
    }
    
    public override void ExecuteCommand(Bolt.Command c, bool resetState) {
        PlayerCommand cmd = (PlayerCommand)c;
        if (resetState) {
            motor.SetState(cmd.Result.Position);
        } else {
            var result = motor.Move(cmd.Input.Horizontal, cmd.Input.Vertical);
            cmd.Result.Position = result.position;
            if (cmd.IsFirstExecution) {
                if(entity.isControlled) {
                    if(cmd.Input.LeftClickDown && !isShooting){
                        isShooting = true;
                        motor.Shoot(transform.position, transform.up);
                        UnityEngine.Debug.Log("SHOOT");
                    }
                    if(cmd.Input.LeftClickUp) isShooting = false;
                }
            }
        }
    }
    And when I do just one click, the UnityEngine.Debug.Log("SHOOT"); is calling 3 times and, by this way, I send 3 bullets.
    Where I can look for a solution ?

    On the bolt sample, I see that Fholm used this function to fire :
    void FireWeapon(PlayerCommand cmd) {
        if (activeWeapon.fireFrame + activeWeapon.refireRate <= BoltNetwork.serverFrame) {
          activeWeapon.fireFrame = BoltNetwork.serverFrame;
          state.Fire();
          // if we are the owner and the active weapon is a hitscan weapon, do logic
          if (entity.isOwner) {
            activeWeapon.OnOwner(cmd, entity);
          }
        }
      }
    I try to repeat it this day but I you have tips, I'm here.

    Thank you for reading.
  • ddd
    Options
    Study the ServerCallbacks.cs, Player.cs, PlayerCallbacks.cs, PlayerController, PlayerMotor from the tutorial.
    Also Utils/ExtenstionMethods (This lets you do connection.GetPlayer()) which is stored in the connection.UserData (ServerCallbacks)

    ServerCallbacks only run's on the server.
    Player.cs is the server's player manager (this is where the server assigns control to the player)
    PlayerController/Motor runs on server/controller/proxy (other players) So for example if you do override Attached() it will run on everyone that is in range (if using AOI/POI ) (server/controller/proxy)