Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Irsan · Apr 20, 2011 at 02:33 AM · rotationpositionsetpoint-and-click

Set position and rotation.

This one must be extremely easy to answer. I have an object in the scene, and I want it so clicking on it will instantly change the position and rotation of the player. So essentially I'm asking both how to instantly change the position and rotation of the player, and how to make the script effect the player instead of itself.

This is for a point-and-click style game, so I want to be able to set these "buttons" all over the scene in order to move the player around. Position and rotation being variables, of course.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by psychentist · Apr 20, 2011 at 04:04 AM

well, it depends on if you know the rotations you want to set the player to, or if you want to manipulate the existing one. Let's just say that you want the right arrow to rotate your player to the right by 90 degrees. fair enough? (you can also use vector3, and Euler3, but I dont feel like looking up the syntax right now. :-P)

Locrot Manager (attach to its own empty object)

static var playerX : float; static var playerY : float; static var playerZ : float;

static var targetX : float; static var targetY : float; static var targetZ : float;

static var targetXLoc : float; static var targetYLoc : float; static var targetZLoc : float;

Player Rotator (attach to the player object)

function Update(){

locrotManager.playerX = transform.rotation.x; locrotManager.playerY = transform.rotation.y; locrotManager.playerZ = transform.rotation.z; }

function Rotate(){

transform.rotation.x = locrotManager.targetX; transform.rotation.y = locrotManager.targetY; transform.rotation.z = locrotManager.targetZ; }

function Move(){

transform.position.x = locrotManager.targetXLoc; transform.position.y = locrotManager.targetYLoc; transform.position.z = locrotManager.targetZLoc; }

Right Arrow (attach to the arrow/button thingy)

function OnMouseDown(){

locrotManager.targetX = locrotManager.playerX; locrotManager.targetZ = locrotManager.playerZ;

if (locrotManager.playerY >= 270){ locrotManager.targetY = locrotManager.playerY - 270; }

else { locrotManager.targetY = locrotManager.playerY + 90; }

PlayerRotator.Rotate(); }

Forward Arrow (attach to the arrow/button thingy)

var targetX : float; var targetY : float; var targetZ : float;

function OnMouseDown(){

locrotManager.targetXLoc = targetX; locrotManager.targetYLoc = targetY; locrotManager.targetZLoc = targetZ;

playerRotator.Move(); }

according to what you were saying, the arrows will be all over the scene, right? if so, then you should be able to figure out where you want each one to move them to and set the target coordinates in the editor, so each arrow can have the same script.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Jean-Fabre · Apr 20, 2011 at 08:44 AM

Hi,

You are speaking about buttons in the scenes, if these buttons are actually representing the spot, then you'd build a script attached to each spot and when the user click on it, it position and rotate the player to match itself.

The script below will just do that.

If you want to move the player to a different location then that spot, you can uncheck useTransform and set position and rotation.

public var player:Transform; public var useTransform:boolean = true; public var position:Vector3; public var rotation:Vector3;

function OnMouseUp () {

  if (player==null){
     return;
  }
  if(useTransform){
      player.position = transform.position;
      player.rotation = transform.rotation;   
  }else{
      player.position = position;
      player.rotation = Quaternion.EulerAngles(rotation);
  }

}

you can create as much dummies as you want, attach this script to them, set its public variables properly, and you'll be able to move your player around from spot to spot as you click on them.

Hope it helps,

Bye,

Jean

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to set a specific rotation? 1 Answer

Objects not always Spawning At Correct Location 2 Answers

Prefab Character position/rotation resets 0 Answers

How to always face player relative to player's rotation and how do I use TransformDirection to move a player regardless of Y-rotation? 0 Answers

Freeze camera 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges