mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-03-05 07:37:17 +00:00
fixing fire direction on clients
This commit is contained in:
parent
b38bf70f8b
commit
a1601341e6
5 changed files with 52 additions and 13 deletions
Assets/Scripts/Behaviours
Docs
|
@ -413,25 +413,36 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
|
||||
|
||||
protected virtual bool TryFire ()
|
||||
{
|
||||
if (m_weapon != null)
|
||||
return this.TryFire(m_weapon.GetFirePos(), m_weapon.GetFireDir());
|
||||
return false;
|
||||
}
|
||||
|
||||
protected virtual bool TryFire (Vector3 firePos, Vector3 fireDir)
|
||||
{
|
||||
Ped ped = m_ped;
|
||||
var weapon = ped.CurrentWeapon;
|
||||
|
||||
|
||||
if (!m_isServer)
|
||||
if (null == weapon)
|
||||
return false;
|
||||
|
||||
if (ped.IsFiring)
|
||||
if (ped.IsFiring) // already firing
|
||||
return false;
|
||||
|
||||
// check if there is ammo in clip
|
||||
if (weapon.AmmoInClip < 1)
|
||||
return false;
|
||||
|
||||
ped.StartFiring ();
|
||||
if (m_isServer)
|
||||
{
|
||||
ped.StartFiring ();
|
||||
|
||||
if (!ped.IsFiring) // failed to start firing
|
||||
return false;
|
||||
if (!ped.IsFiring) // failed to start firing
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
// reduce ammo
|
||||
weapon.AmmoInClip --;
|
||||
|
@ -443,18 +454,40 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
weapon.UpdateGunFlashRotation ();
|
||||
|
||||
// fire projectile
|
||||
F.RunExceptionSafe( () => weapon.FireProjectile () );
|
||||
if (m_isServer)
|
||||
F.RunExceptionSafe( () => weapon.FireProjectile (firePos, fireDir) );
|
||||
|
||||
// send fire event to server
|
||||
if (Net.NetStatus.IsClientOnly)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// play firing sound
|
||||
F.RunExceptionSafe (() => weapon.PlayFireSound() );
|
||||
|
||||
// notify clients
|
||||
Net.PedSync.OnWeaponFired(m_ped, weapon, weapon.GetFirePos());
|
||||
if (m_isServer)
|
||||
Net.PedSync.OnWeaponFired(m_ped, weapon, firePos);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void OnClientTriedToFire(Vector3 firePos, Vector3 fireDir)
|
||||
{
|
||||
if (null == m_weapon)
|
||||
return;
|
||||
|
||||
if (m_weapon.AmmoInClip < 1)
|
||||
return;
|
||||
|
||||
if (!m_ped.IsFiring)
|
||||
m_ped.StartFiring();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void RotateCamera ()
|
||||
{
|
||||
|
|
|
@ -287,6 +287,9 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
|
||||
public virtual void OnWeaponFiredFromServer(Weapon weapon, Vector3 firePos)
|
||||
{
|
||||
if (m_ped.IsControlledByLocalPlayer)
|
||||
return;
|
||||
|
||||
// update gun flash
|
||||
if (weapon.GunFlash != null)
|
||||
weapon.GunFlash.gameObject.SetActive (true);
|
||||
|
|
|
@ -8,6 +8,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
|
||||
void StartFiring ();
|
||||
|
||||
void OnClientTriedToFire(Vector3 firePos, Vector3 fireDir);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -592,13 +592,14 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
}
|
||||
|
||||
public virtual void FireProjectile ()
|
||||
public void FireProjectile ()
|
||||
{
|
||||
// obtain fire position and direction
|
||||
|
||||
Vector3 firePos = this.GetFirePos ();
|
||||
Vector3 fireDir = this.GetFireDir ();
|
||||
this.FireProjectile(this.GetFirePos(), this.GetFireDir());
|
||||
}
|
||||
|
||||
public virtual void FireProjectile (Vector3 firePos, Vector3 fireDir)
|
||||
{
|
||||
|
||||
// raycast against all (non-breakable ?) objects
|
||||
|
||||
RaycastHit hit;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
- add ability for client to request:
|
||||
|
||||
- roll state: client doesn't know the direction of rolling ; when doing more rolls one after another, client doesn't play anim anymore ; sometimes rolling continues even if WASD keys are not pressed ;
|
||||
- roll state: when doing more rolls one after another, client doesn't play anim anymore ; sometimes rolling continues even if WASD keys are not pressed ;
|
||||
|
||||
- shooting is inaccurate - clients should send fire event with fire pos and fire dir
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue