Author Topic: Making player point at a specific coordinate  (Read 955 times)

(In a scenario where the server could control the direction someone pointed) how could I
make someone look at a specific coordinate on the map? It's interesting because I thought
it would be easy but it seems more difficult than I imagined.

you can make someone turn toward something, but making them actually look at it is unnecessarily difficult because afaik there's no straightforward way to directly control a player's pitch (up/down look angle)

unless there have been breakthroughs in this area since i last checked up on it, you'd probably have to settle for only orienting the player in the right direction

you can make someone turn toward something, but making them actually look at it is unnecessarily difficult because afaik there's no straightforward way to directly control a player's pitch (up/down look angle)

unless there have been breakthroughs in this area since i last checked up on it, you'd probably have to settle for only orienting the player in the right direction
Ok, so if I get what you're saying I can only have someone look in the X and Y directions...
how would one make a player turn to (the general direction) of a coordinate on the map then?

you can make someone turn toward something, but making them actually look at it is unnecessarily difficult because afaik there's no straightforward way to directly control a player's pitch (up/down look angle)

unless there have been breakthroughs in this area since i last checked up on it, you'd probably have to settle for only orienting the player in the right direction
It's not that there's no straightforward way to control a player's pitch.
There isn't a way at all.


If maybe we had AIConnections still, you could have it control, look, and give control back to the GameConnection all in one go and that /might/ work? But no sense in figuring that out since we don't have AIConnections anymore.

Ok, so if I get what you're saying I can only have someone look in the X and Y directions...
how would one make a player turn to (the general direction) of a coordinate on the map then?
You set their transform to still have the same position, but change the rotation part of it so that they're looking in that direction.

It's not that there's no straightforward way to control a player's pitch.
There isn't a way at all.


If maybe we had AIConnections still, you could have it control, look, and give control back to the GameConnection all in one go and that /might/ work? But no sense in figuring that out since we don't have AIConnections anymore.
yeah i knew there used to be a way with AIConnections before they were removed for some reason, spent a long time scratching my head with a bud on that once, wasn't sure if there was still some possible trickery by replacing the player with a bot and using the aiming functionality there or smth

Ok, so if I get what you're saying I can only have someone look in the X and Y directions...
how would one make a player turn to (the general direction) of a coordinate on the map then?
some simple trigonometry will do it. get the difference between their X and Y coordinates and use mAtan to find the angle. the default camera events have some reference code that does this (lines 22-34 in Event_Camera_Control/server.cs); you can either scrap the parts that mess with Z coordinates/X rotation or keep them, shouldn't make a difference

Thanks, this is really useful. it's funny because I'm learning about trigonometry atm,
interesting to see it come into play

kind of surprising there isn't a function that sets the camera angle
is it possible to have the client lose control of the player, have a bot take it over and look somewhere, then give the client control again?
I didn't see much into setting the player's control to an AI while I was glancing through it

A hacky way to do it would be to spawn a bot in the player's position then move the player, and client camera accordingly, then have the bot look at the exact point. Then, get the transform of the bot, delete the bot and set the player's transform to the transform you got from the now deleted bot.


looks like getTransform only gives position + xy rotation
in which case you could probably just math the angle instead of making a bot do it

looks like getTransform only gives position + xy rotation
in which case you could probably just math the angle instead of making a bot do it
player objects, like several types of objects (eg bricks and items), are locked to only rotate about the Z axis (there's a term for this i can't remember). even if you change their transform to rotate them around the X or Y axes, it doesn't happen, cus they're constrained. players looking up/down is handled completely separately, and the physical appearance of vertical aiming is just a special animation. i do wonder why there's no way to directly write the player's eye vector tho
« Last Edit: May 28, 2017, 06:14:32 AM by otto-san »

honestly just make an aiplayer, and replace the player of the client with it (set controlobject, set client.player, etc). you can now do full transform controls on them.

you can also use the hole bot functions like lookAtObject and such too