Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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
0
Question by Narshyl · Mar 27, 2012 at 11:22 AM · fpslaunchcannon

Launching my character with a cannon.

Hello guys, i started unity just a couple of weeks ago, i want to make a cannon that launches my player to the next part of my map, i seem to be unable to do this. can anyone help me out.

(i tried to google it but nothing comes up)

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Viluredfish · Mar 27, 2012 at 01:37 PM

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddForce.html

look to this, just check if you'r Character got a RigidBody.

it can help you too : http://unity3d.com/support/documentation/ScriptReference/ForceMode.Impulse.html

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 reptilebeats · Mar 27, 2012 at 01:56 PM

there are a few different ways you can do this depending on what you are looking for, if say for instance you want the cannon to shoot the player to the same location every time then your best bet would be to animate it with some nice particle effects, explosion and around the character.

you could even go as far as making the background blur a bit to make it even better but theres a million different ways for the effect depending on the game, i wouldnt want stars as the explosion if im making a horror game but i would if im making a fun cartoon game.

the other way that i use for other objects in my game is simply applying force to the character, so you could apply force to the character at the cannons direction, however this isnt going to be accurate, as its real time phyisics and it depends on your character.

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 FlavioVolpeJr · Oct 16, 2020 at 08:19 PM

I spent about 3 days trying to make this script, now that I got it, it has worked well in my project. Here he goes to help anyone looking for the same thing. Remembering that it is for 3D games.

 using System;
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 
 public class PlayerControlCannon : MonoBehaviour
 {
     public Rigidbody character;
     public Transform shootingPart;
     public bool manualControl;
     public float rotatingSpeed = 100f;
     public float shotForce = 50f;
 
     private bool isShooting = false;
     private float backColliderDelay = 0.05f;
 
 
     public void Start()
     {
 
     }
 
 
     public void Update()
     {
 
         if (Input.GetButtonDown("Fire1") && isShooting == true)
         {
 
             StartCoroutine("Shooting");
 
             print("Fired");
 
         }
     }
 
     IEnumerator Shooting()
     {
 
         character.transform.position = transform.position;
         character.transform.rotation = shootingPart.rotation;
 
         character.AddForce(transform.forward * shotForce, ForceMode.VelocityChange);
 
         character.transform.parent = GameObject.FindWithTag("Player").transform;
         character.GetComponent<MeshRenderer>().enabled = true;
         character.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.None;
         character.GetComponent<Collider>().enabled = false;
 
         yield return new WaitForSeconds(backColliderDelay);
 
         character.GetComponent<Collider>().enabled = true;
 
         isShooting = false;
 
     }
 
     public void OnTriggerStay(Collider other)
     {
         if (other.gameObject.CompareTag("Player"))
         {
 
             other.gameObject.transform.parent = transform;
             other.gameObject.transform.localPosition = new Vector3(0f, 0f, 0f);
             other.gameObject.transform.localRotation = Quaternion.identity;
             other.gameObject.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
             other.gameObject.GetComponent<MeshRenderer>().enabled = false;
 
             isShooting = true;
 
         }
 
         if (manualControl == true)
 
         {
             // Move to the right
             if (Input.GetButton("Horizontal") && Input.GetAxisRaw("Horizontal") > 0)
             {
                 transform.Rotate(Vector3.up * rotatingSpeed * Time.deltaTime);
             }
 
             // Move to the left
             else if (Input.GetButton("Horizontal") && Input.GetAxisRaw("Horizontal") < 0)
             {
                 transform.Rotate(Vector3.down * rotatingSpeed * Time.deltaTime);
             }
 
             // Move to the up
             else if (Input.GetButton("Vertical") && Input.GetAxisRaw("Vertical") < 0)
             {
                 transform.Rotate(Vector3.right * rotatingSpeed * Time.deltaTime);
             }
 
             // Move to the down
             else if (Input.GetButton("Vertical") && Input.GetAxisRaw("Vertical") > 0)
             {
                 transform.Rotate(Vector3.left * rotatingSpeed * Time.deltaTime);
             }     
         }
     }
 }

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

7 People are following this question.

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

Related Questions

Launching player with cannon 2 Answers

Missile not launching. 1 Answer

iPhone tracking device in Unity Environment 1 Answer

Is there a way to create applications that run on fixed frame rate of 60fps on iOS? 1 Answer

Performance issue loading resource 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