c#


Object flies off to infinity after rotation


I am trying to make a 2D "Ghost Object" in Unity that moves to where the player's mouse position is (while snapping to a grid) and rotates when the mouse wheel is rotated. When the player clicks, it would then create the "Real Object" in its place.
The problem is that as I start rotating the object, it becomes inexplicably unstable and eventually flies off screen before reaching infinity. When not rotated, it behaves perfectly.
Since the movement code should work regardless of direction, I have no idea why it is flying off screen.
Relevent code (C#):
Vector3 rawPos = cam.ScreenToWorldPoint (Input.mousePosition);
transform.Rotate(0,0,50*Input.GetAxis ("Mouse ScrollWheel"));
Vector3 targetPos = new Vector3 (Mathf.RoundToInt(rawPos.x),Mathf.RoundToInt(rawPos.y),10);
transform.Translate (targetPos-transform.position);
This is probably something obvious, but I'm still a bit new to this.
Thanks in advance for any help.
Edit: I suppose I should note that this is occurring in FixedUpdate.
Solved the problem by changing
transform.Translate
to
transform.position = targetPos
Works just as well.

Related Links

Queue showing empty
Request.IsAjaxRequest() always returns false
Download WebPage with Javascript [duplicate]
How to Remove Apply Button in a Telerik RadColorPicker From Code Behind
Unable to cast object of type 'System.Data.Entity.Infrastructure.DbQuery`1[]' to type 'System.Collections.Generic.IEnumerable
Change Model Data In a Controller Method
Allow caller to supply LINQ predicate without knowing value
How to retrieve data from sql server database and manipulate it in c#?
How to publish the WSDL at the public domain name in a WCF service hosted in an Azure worker role?
Are PlaybackSettings persistent between tests?
When to use ref and out? [duplicate]
Authorize Attribute with Roles not working?
WebRequest will not pass headers
Delay in button activation in Asp.net
how to transfer data from HTML tag to c# in MVC
WPF Toolkit Chart using ControlTemplate don't show my LineSeries

Categories

HOME
django-middleware
watson-iot
hiveql
overrides
google-docs-api
ebay
powerquery
select2
mongoimport
core-data
fetch
ndepend
repeater
console-application
k-means
scotty
bootstrap-datetimepicker
webgl-earth
bug-reporting
cherrypy
mattermost
ng-tags-input
functional-dependencies
android-wear-2.0
rancher
gulp-jshint
login-required
voyager
angularjs-resource
android-geofence
javafxports
maven-2
realloc
lfe
azure-web-roles
susy
vertical-alignment
collation
quartz
flume-ng
taleo
chrome-custom-tabs
android-doze-and-standby
g77
import.io
bioperl
ajv
cosign-api
git-cherry-pick
nsoperationqueue
containstable
apache2-module
android-contentresolver
recode
tvp
javapackager
gitk
winforms-interop
dpkt
eaaccessory
sparkcore
data-representation
copy-on-write
backtrace
gnip
vundle
javacompiler
parallel-port
ant-contrib
data-layers
myrrix
infomaker
azure-pack
asp.net-4.0
biztalk-deployment
orchestration
jquery-ui-map
parsec
zipstream
javah
mediastreamsource
activescaffold
pitch-shifting
linq-to-mysql
dynamic-scope
data-formats
script-tag
user-preferences
vista64

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile