c#


Get position from player forward at constant distance


The simple way to get player front position at specific distance
Vectro3 forward = player.transform.forward * distance;
Vector3 newPlayerFronPosition= player.transform.position + new Vector3(forward.x, forward.y, forward.z);
newPlayerFronPosition= new Vector3(newPlayerFronPosition.x, newPlayerFronPosition.y - 4f, newPlayerFronPosition.z);
navigationCanvas.transform.position = newPlayerFronPosition;
navigationCanvas.transform.rotation = camRotationToWatch.transform.rotation;
its actually working fine but the problem is as my player move up or down the navCanvas become appear ver near to my player. How to mainitain spcific distance all the time.?? that no matter player look above or down the navcanvas display at specfic distance.(position)
disatnceUICam = Vector3.Distance(newPlayerFronPosition, player.transform.position);
I also logged the distance and surprisingly it the distance is changing when i am moving up or down. its changing from 6 to 12 as i am looking up to down.
If I've understood you correctly, and you want a point on in front of your player transform on the X Z Plane a set distance from the forward of your player, you should try something like this:
Vector3 horizontalForward = new Vector3(
player.transform.position.x + player.transform.forward.x,
player.transform.position.y,
player.transform.position.z + player.transform.forward.z
).normalized * distance;
I suspect what you're describing is occurring because the transform of your 'player' variable is connected to the direction of your game camera. As the camera looks up, the world position of your forward changes relative to the camera. Using just the X and Z will produce a varying distance as your camera transform rotates around the X Axis. Perhaps this diagram will illustrate what I mean a little better:
Sorry the hypotenuse is a little wonky but you get the idea right?

Related Links

JAMS Scheduler: No such host is known
2D Character falls off the map in Unity3D
How can I round a float value stored in a string from a data bound source in xaml
“unsafe code may only appear if compiling with /unsafe”
Mock ServerVariables in the HttpContext.Current.Request
Is boxing involved when calling ToString for integer types?
Escape a path with “..” (parent) in C#
How to use ViewModel with DropDownListFor
XmlSerializer is removing elements
How to download the attachments of a email using Mailkit
Else If statement is invalid, possible method required? [closed]
Construction of Gtk#-FileChooserDialog crashes application on Windows
BeginSend taking too long till callback
Linq search for any of words in term
Can we use the Portable class library (Xamarin.Forms Portable) to share UI with ASP.Net application? How?
Webform Master page MVC PartialRender server event not firing

Categories

HOME
drupal
classification
model-view-controller
azure-active-directory
typo3
domain-driven-design
customization
apache-storm
conceptual
livecharts
nltk
arguments
swap
virtualhost
token
select2
wowza
camunda
jinja2
passbook
bootstrap-datetimepicker
fastboot
datanucleus
nsopenpanel
drombler-fx
large-files
textview
urhosharp
favorites
abide
linkurious
fisheye
pyexcel
web-technologies
paperclip
colorbox
peerjs
smooth-streaming
bootstrap-carousel
mef
text-formatting
pyopenssl
cloudconvert
jscoverage
senti-wordnet
petapoco
multi-select
disassembly
catalyst
group
cedar-bdd
blackberry-webworks
camellia
containstable
std
encode
magnet-uri
javapackager
taverna
personality-insights
adempiere
traminer
dnvm
jsoncpp
android-filterable
eaaccessory
nmock
photogrammetry
glog
tidesdk
optimistic-locking
launcher
nsurlrequest
nsnotificationcenter
rpt
nomachine
ekevent
xcode5.1
wpd
azure-scheduler
proj4
gpl
hypertable
xcode4.6.3
databus
sup
sqlbuddy
object-tag
moss2007-security
lwp
marathontesting
azure-appfabric
database-agnostic
scalable

Resources

Encrypt Message