SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
88 stars 18 forks source link

SteamCall for getting by server RaycastInfo/InputInfo on clientside by request #2569

Closed Sl4vP0weR closed 3 years ago

Sl4vP0weR commented 3 years ago

Physics.RaycastAll(ray, range, -1, QueryTriggerInteraction.Collide); when player watching on zombie returns 0 hits(or some hits of player). Something wrong or it should be like this?

SDGNelson commented 3 years ago

Only the CharacterController is loaded on the dedicated server, no character mesh unfortunately.

Sl4vP0weR commented 3 years ago
[SteamCall(ESteamCallValidation.ONLY_FROM_SERVER, legacyName = "tellRaycastRequest")]
public static void ReceiveRaycastRequest(Vector3 origin, Vector3 direction, float distance, int layerMask)
{
var raycastInfo = DamageTool.raycast(new Ray(origin, direction), distance, layerMask, Player.player);
Player.player.input.sendRaycast(raycastInfo, ERaycastInfoUsage.ServerRequest);
}

static readonly ClientStaticMethod<Vector3, Vector3, float, int> SendRaycastRequest = ClientStaticMethod<Vector3, Vector3, float, int>.Get(new ClientStaticMethod<Vector3, Vector3, float, int>.ReceiveDelegate(PlayerInput.ReceiveRaycastRequest));

[NetInvokableGeneratedMethod("ReceiveRaycastRequest", ENetInvokableGeneratedMethodPurpose.Read)]
public static void ReceiveRaycastRequest_Read(in ClientInvocationContext context)
{
    NetPakReader reader = context.reader;
    reader.ReadClampedVector3(out var origin);
    reader.ReadNormalVector3(out var direction);
    reader.ReadFloat(out var distance);
    reader.ReadInt32(out var mask);
    PlayerInput.ReceiveRaycastRequest(origin, direction, distance, mask);
}
Sl4vP0weR commented 3 years ago

Will be better to do RaycastAll too

SDGNelson commented 3 years ago

What do you have in mind to use it for?

Sl4vP0weR commented 3 years ago

What do you have in mind to use it for?

Raycast on the player side will have all meshes and will give the correct Raycast result. That SteamCall will be perfect for plugin developers, cuz will give us view from player side.

LenzMix commented 3 years ago

We want moooore methods for servers!

surv0013 commented 3 years ago

@SDGNelson don't listen to them, they are Russian hackers, they want to take control of the players' minds.

Sl4vP0weR commented 3 years ago

@SDGNelson don't listen to them, they are Russian hackers, they want to take control of the players' minds.

c'mon, stop it, only you're russian hacker here

Sl4vP0weR commented 3 years ago

What do you have in mind to use it for?

@SDGNelson, with this I can get more info about what player see

iBowie commented 3 years ago

But how exactly you expect raycastInfo to be sent to server? It contains transform that only exists on client, so it WILL be out of sync, and to sync it you should send ALL transforms or ALL gameobjects attached to it that exist on client to properly sync it.

Sl4vP0weR commented 3 years ago

But how exactly you expect raycastInfo to be sent to server? It contains transform that only exists on client, so it WILL be out of sync, and to sync it you should send ALL transforms or ALL gameobjects attached to it that exist on client to properly sync it.

Like in UseableGun.ballistics method. player.input.sendRaycast or like that. Unturned already synchronize some gameobjects, on serverside it's only by info, without rendering.

Sl4vP0weR commented 3 years ago

From SDG.Unturned.PlayerInputPacket:

RaycastInfo info = this.clientsideInputs[i].info;
ERaycastInfoUsage usage = this.clientsideInputs[i].usage;
if (info.player != null)
{
    writer.WriteEnum(ERaycastInfoType.PLAYER);
    writer.WriteEnum(usage);
    writer.WriteClampedVector3(info.point, 13, 7);
    writer.WriteNormalVector3(info.direction, 9);
    writer.WriteNormalVector3(info.normal, 9);
    writer.WriteEnum(info.limb);
    writer.WriteSteamID(info.player.channel.owner.playerID.steamID);
}
else if (info.zombie != null)
{
    writer.WriteEnum(ERaycastInfoType.ZOMBIE);
    writer.WriteEnum(usage);
    writer.WriteClampedVector3(info.point, 13, 7);
    writer.WriteNormalVector3(info.direction, 9);
    writer.WriteNormalVector3(info.normal, 9);
    writer.WriteEnum(info.limb);
    writer.WriteUInt16(info.zombie.id);
}
iBowie commented 3 years ago

If it's possible and won't hit network and cpu usage on client then ok

Sl4vP0weR commented 3 years ago

If it's possible and won't hit network and cpu usage on client then ok

It will be fine. It's like when the player is shooting.

Sl4vP0weR commented 3 years ago

@SDGNelson Will you add this SteamCall?

rube200 commented 3 years ago

First of all, I don't see why this SteamCall is being added, as the server already has practically all the client information. Second, what would be the frequency of this call?

Sl4vP0weR commented 3 years ago

First of all, I don't see why this SteamCall is being added, as the server already has practically all the client information. Second, what would be the frequency of this call?

  1. I need this to get a zombie or something else that doesn't have a mesh on serverside.
  2. Idk, when the server needs to raycast - the server will get it.
rube200 commented 3 years ago

Atm is possible to get all zombies position and u raycast the point at where the player is aiming.

SDGNelson commented 3 years ago

Raycast on the player side will have all meshes and will give the correct Raycast result. That SteamCall will be perfect for plugin developers, cuz will give us view from player side.

What do you want to use it for though? Is it specifically something zombie related as in the OP?

Sl4vP0weR commented 3 years ago

What do you want to use it for though? Is it specifically something zombie related as in the OP?

Not at all, zombie was only as an example, I need to know what around of the player on his side(I can't do that on serverside because serverside doesn't have all meshes) when he did a punch.

SDGNelson commented 3 years ago

Okay getting closer, what do you want to do when a player punches? What do you want to use it for?

Sl4vP0weR commented 3 years ago

Okay getting closer, what do you want to do when a player punches? What do you want to use it for?

Stop asking me, why I need this, it's for my plugin, I don't want to give my plugin idea to the public.

SDGNelson commented 3 years ago

Stop asking me, why I need this, it's for my plugin, I don't want to give my plugin idea to the public.

If you want to keep it secret you can email me nelson@smartlydressedgames.com, but otherwise it would be insane to add features without an actual use case.

SDGNelson commented 3 years ago

@Sl4vP0weR did send an email, but I do not think they are good reasons to add a feature like this to the game.

Sl4vP0weR commented 3 years ago

@Sl4vP0weR did send an email, but I do not think they are good reasons to add a feature like this to the game.

@SDGNelson, Anyways, think about this just more times, it will be very useful for developers, ideas that I sent to you is already will add more interest in gameplay. This SteamCall can have many usages in the development community.