Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 waittobi · Dec 21, 2016 at 03:04 AM · c#movementinstantiatescriptingbasics

Moving with instantiated projectile

Hi, what Im trying to get done is make my player moves with the instantiated object projectile as if he turned into it to travel for a couple seconds then turns back to normal

Comment
Add comment · Show 5
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 TheUltimateKerbonaut · Dec 22, 2016 at 06:14 PM 0
Share

Is the game you are working on first person or not? Are you basically trying to get the camera to follow a bullet/missile/etc and then go back to the player or is your game 3rd person?

avatar image waittobi TheUltimateKerbonaut · Dec 22, 2016 at 06:46 PM 0
Share

i would consider it more of a 2.5d side scroller .. i want my character to kinda like travel with the projectile as if he became it and shoot himself forward

avatar image Cherno waittobi · Dec 22, 2016 at 07:05 PM 1
Share

Well...? :) If you use a rigidbody to move your character, simply add the appropriate force vector to it. If using a CharacterController, move him with a CoRoutine.

avatar image TheUltimateKerbonaut · Dec 24, 2016 at 01:53 PM 0
Share

Hi again. Have you solved this issue yet or not? I would be happy to provide some code if need be :).

avatar image waittobi TheUltimateKerbonaut · Dec 24, 2016 at 03:06 PM 0
Share

i couldn't get exactly want i wanted but i used

myRb.AddRelativeForce(Vector3.forward * warpSpeed );

and it get give me like a kinda forward teleport movement which wasn't what i wanted .. but id like to try your code out maybe you have something better :) @TheUltimate$$anonymous$$erbonaut

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by TheUltimateKerbonaut · Dec 24, 2016 at 04:55 PM

I think this bit of code bellow might help. Please note some variables you might need to change to your own, like the player GameObject. It basically just makes the player follow the projectile, with an optional offset (you could just set it to 0.0f if you didn't want it).

 private bool needToFollowProjectile;
 public GameObject player;
 private GameObject projectile; // Code will tell what the gameobject is, so no need to make it public.

 public float playerProjectileFollowOffsetX;
 public float playerProjectileFollowOffsetY;
 public float playerProjectileFollowOffsetZ;

 public void onProjectileFire() { // Basically, just imagine this is the function or peice of code that executes when projectile is fired.
     needToFollowProjectile = true; // We just need to know if we need to make the player follow, thats all.
     projectile = instantiatedPrefab; // I imagine when you instantiate the prefab, you have some sort of gameobject you can use as a variable.
 }

 public void LateUpdate() { // Calls after Update() meaning it is an ideal place to make one gameobject follow another, without any jittering/lag.
     if (needToFollowProjectile) {
         player.transform.position = new Vector3 (projectile.transform.position.x + playerProjectileFollowOffsetX, projectile.transform.position.y + playerProjectileFollowOffsetY, projectile.transform.position.z + playerProjectileFollowOffsetZ);
     }
 }

By the way, to find out more about LateUpdate(), visit here. If you need any more help just ask :).

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 waittobi · Dec 28, 2016 at 11:38 PM

Sorry for a late reply i've been around family and not around a cpu ... i've been playing around with your code but everything i was trying wasn't working .. maybe if i show u my script that i'm trying to add it too it'll help... this script is attached to my player @TheUltimateKerbonaut ... {

 public Rigidbody chakraBlastPrefab;
 public Transform spawnPoint;
 public float warpSpeed;

 Rigidbody myRb;

 AudioSource source ;
 public AudioClip chakraSound;

 void Awake()
 {
     source = GetComponent<AudioSource> ();

     myRb = GetComponent<Rigidbody> ();
 }

 void  Update ()
 {

     if(Input.GetKeyUp("z"))
     {
         Shoot ();

         }
         
  void Shoot ()
 {
     Rigidbody chakraBlast = Instantiate(chakraBlastPrefab, spawnPoint.position, Quaternion.identity ) as Rigidbody ;
     source.Stop ();
     source.PlayOneShot (chakraSound);

     chakraBlast.AddForce(spawnPoint.right * 2000);
 

 }

     }

}

Comment
Add comment · Show 5 · 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 TheUltimateKerbonaut · Dec 30, 2016 at 04:46 PM 0
Share

What is wrong with the code I provided? Any error messages? Have you assigned all the variables in the editor. I apologise for not actually testing the code (was away too, which is also the reason for late reply), will try it out when I can. What actually happens when the code is run? Try the standard Debug.Log() in various places to see if any code isn't executing correctly.

avatar image waittobi TheUltimateKerbonaut · Jan 02, 2017 at 10:10 PM 0
Share

sorry been away..... When i added your code it worked a bit but it always jump my player just back to the same place regardless of my position which was 0,0,0, i want it to follow my projectile @TheUltimate$$anonymous$$erbonaut

avatar image TheUltimateKerbonaut waittobi · Jan 03, 2017 at 07:16 PM 0
Share

So, basically, the character follows the projectile, then doesn't go back to his original position? I didn't include that into the code, you would just have to modify player's transform.position to put him back where he was using a temporary variable that stores original position.

Show more comments
Show more comments

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

272 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making a bubble level (not a game but work tool) 1 Answer

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Spawn Ground right next to current ground 1 Answer

How do I setup fixed movement between predetermined tiles? 0 Answers


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