Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by Raul 1 · Aug 20, 2010 at 04:54 AM · vector3fpsmoveaddtank

Move 'Player' To new position.

So im making a large BattleField style RTS and i have gotten my tank entering system working but i need a way so when you get out it places the 'player' which is a fps controller prefab next to the tank.

Thanks in advance.

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
1

Answer by · Aug 20, 2010 at 06:30 AM

As 0V3RWR173D said, it's a bit difficult to give you an exact answer without knowing how your system is setup.

var player : GameObject;

function OnStart () { player = GameObject.Find("Player"); }

function Update () { if (Input.GetKeyDown("e") /&& player is in tank/) // commented out for your code to replace { tank = GameObject.Find("Tank"); // finds the GameObject named if ( tank ) { player.position = (tank.position + (2,0,0)); player.rotation = tank.rotation; // make the player visible here } } }

This setup will test when 'e' is pressed, find the GameObject named 'Tank' and teleport the Player prefab 2 units to the right of its current position with the same rotation. You'll need to specify the Player prefab on the GameObject you attach this script to. You'll also want to update the "/&& player is in tank/" with a check that works with your code to determine whether the player is inside the tank (or you'll get teleported every time it's pressed). One obvious limitation is that if the tank is on a slope, the player could be set to a position underneath/inside the terrain. Games typically deal with this issue through a set of raycast checks before allowing the Player to exit the vehicle.

Comment
Add comment · Show 2 · 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 Raul 1 · Aug 20, 2010 at 04:10 PM 0
Share

Ok, The 'Player' is still in play, just invisible. I just want to change the position of it from a script not attached to the 'player'.

avatar image · Aug 21, 2010 at 01:22 AM 0
Share

I've updated the script to teleport the player rather than spawn it. You'll need to change the "player = GameObject.Find("Player");" line to match the name of your player character object (or use FindWithTag) and make the player visible again (where commented) by doing the opposite of however you're making them invisible. Let me know if you have any troubles.

avatar image
0

Answer by 0V3RWR173D · Aug 20, 2010 at 05:17 AM

You can use javascript to change the location. If you don't know how to script then it will be difficult. Depending on what you want to do, it may be difficult if you are new to unity. You can use:


function Update () {
if (Input.GetKeyDown("e")) {
transform.position = Vector3(0, 0, 0);
}
}

The Update means that it will check every frame to see if the "if" statement is true. After the if statement "(Input.GetKeyDown("e"))" means that it will check if you pressed the "e" key on your keyboard. "transform.position" is referring to the position of the object that the script is attached to. "= Vector3(0, 0, 0)" means that you are changing the position of the object to 0 on each axis.

I don't know your current situation so I cannot help you any more for the moment. You can also have an object broadcast a message to your player when something happens (ex. the player collides with a certain object or leaves a certain area).

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

Move character by X units on the left 1 Answer

Vector3 and Quaternion issues. 2 Answers

Vector3.lerp doesn't work 1 Answer

Move empty object random 1 Answer

How to Make an Object turn Toward Another 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