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 Charles_Gams · Mar 26, 2013 at 11:52 PM · movementarraybounceattack

Bounce Attack Like in Sonic the hedgehog

I'm looking to create a bounce attack like in sonic the hedgehog when certain conditions are met you can bounce attack on enemies and certain obtacles. The way I'm planning to do this is:

  • create a variable that detects if its within a certain raidus. Then you can bounce attack.

-Bounce attack only happens when you have pressed the jump button along with the button to bounce attack(if that makes sense.

-Then this is where i'm not sure how to implement the feature of moving my character towards the enemy smoothly. Also just like the bounce attack in sonic it is loopable meaning you can bounce attack one enemy then other as along as its within the radius for bounce attack.

I know i might need some sort of array I just need guidance on what i should be looking at and the actual movement of the player towards the enemy is the crucial part the way i see it.

alt text

972790_20101004_embed018.jpg (33.9 kB)
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
2
Best Answer

Answer by Chronos-L · Mar 27, 2013 at 01:09 AM

Its been a while since I played Sonic, I will not remember the exact sequence of action from the game, instead I will build my answer from the details you have provided.


I have answered a question on chain attack, it might not be exactly the same, but it is worth taking a look at. I am going to use the same technique from that question and modify it to fit your question.


Preparation

  1. Create a trigger sphere prefab

  2. Animate the sphere to scale up ( start from 0 to MaximumRange ), so the effect will strike the closest enemy first

    Steps

    Assumption: the attack occurs when you are inAir/isJumpinng and you pressed an attack button (in this example, A-key)*

  3. Press jump, character isJumping

  4. Press A, spawn a trigger-sphere

  5. If trigger-sphere hit a destructible-object, send a message to character (search for target, this will make your character hit the nearest target)

  6. Move character towards the destructible-object, (hit)

  7. When character hit the destructible-object, move the character upward (bounce)

  8. If A is still pressed, restart from Step-2

    Sample Script

    Trigger script*

    public class TriggerSphere : MonoBehaviour { public GameObject character;

     void OnTriggerEnter( Collider other ) {
           if( other.gameObject.CompareTag("CanHit") ) {
     
              /* Note: A */ 
     
              character.SendMessage("SetBounceTarget", other.gameObject);
              Kill();
           }
        }
     
        //Call this using an animation event, just in case the sphere strike nothing at all
        void Kill() {
           Destroy(gameObject);
        }
     }
    
    

Character Script

 public class Character : MonoBehaviour {
    public TriggerSphere ts;
 
    private bool isJumping = false;
    private GameObject moveToward;
    void Update() {
       ...

       if( isJumping && Input.GetKeyDown(KeyCode.A) && moveToward == null ) {
          TriggerSphere tsClone = Instantiate( ts, transform.position, Quaternion.identity );
          tsClone.character = gameObject;
       }
 
       if( moveToward != null ) {
          /* Note : B */
       }
    }
 
    void OnCollisionEnter( Collision collision ) {
       if( collision.gameObject.CompareTag("CanHit") ) {
          isJumping = false;
          /* Note : C */
       }
    }

    void SetBounceTarget( GameObject go ) {
       moveToward = go;  
    }
 }



Note

A

You need to use a raycast to check there is no obstacle between your character and the destructible-object. You should hit the closest and non-obstructed destructible-object.

B

Do a calculation on how to move toward a gameobject, you can use Google to assist you

C

When you have hit a destrutible-object, you will need to return your character back to the jumping-state ( applying force, setting variables to true, etc. Whatever you are using to making your character jump )

Comment
Add comment · Show 32 · 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 Chronos-L · Mar 27, 2013 at 01:12 AM 0
Share

In this condition:

 if( isJumping && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A) && moveToward == null ) {
    ...
 }

In Input.Get$$anonymous$$eyDown(),user need to press A every time to bounce; If Input.Get$$anonymous$$ey() is used ins$$anonymous$$d, player will need hold to A to keep on bouncing.

avatar image Charles_Gams · Mar 27, 2013 at 01:18 AM 0
Share

Honestly thats spot on I'm working on it now and just viewed your answer and it makes alot of sense so far i've got my character moving towards the enemy when the button is pressed which is great and just like you mentioned i need apply the right forces so its accurate according to the key presses pressed.

Didn't think about the raycast being used to detect if theres an object obstructing so thanks alot honestly !! :D

avatar image Charles_Gams · Mar 27, 2013 at 01:21 AM 0
Share

and its very detailed explanation thanks !!

avatar image Chronos-L · Mar 27, 2013 at 01:51 AM 0
Share

Good luck and Godspeed. I am glad that I could help.

avatar image Charles_Gams · Mar 28, 2013 at 03:46 AM 0
Share

@ Chronos-L Hey I've basically got like 90% of the bounce attack working but my only issue is the calculation to move the gameobject because right now it snaps to the target rather than move towards the target without snapping if that makes sense .

I know its ideally to do with this part of my code:

transform.position = Vector3.Lerp(transform.position,target.position, step);

i've also used Vector3.$$anonymous$$oveTowards but its the same thing

the variable step is: var step = bouncespeed extraspeed Time.deltaTime;

I'm wondering if its something to do with the time or movement i would be happy if i was given guidance on this part then i believe everything should work fine

Show more comments
avatar image
0

Answer by Charles_Gams · Apr 01, 2013 at 08:25 AM

Okay thanks I've got a perfect bounce attack with no delays now

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 iyenal222 · Sep 12, 2015 at 09:11 AM 0
Share

Can you give a final script of the ho$$anonymous$$g attack with the improvements in your comments please ? Thanks

avatar image sonicjason255 · Dec 02, 2017 at 12:07 AM 0
Share

I don't want to be a name Nazi or something but I though you were talking about the bounce attack from sonic adventure and you were talking about the ho$$anonymous$$g attack(but now that i mention it does anyone know how to make the bounce attack from adventure as well)

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

13 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

Related Questions

Make an object "bounce" off walls?[Solved] 0 Answers

Moving an Object to the vector of other objects on button press using a vector3 array? 0 Answers

Bounce into the air 1 Answer

How to have a GameObject follow a path with c#? 3 Answers

How do I store Vertices in an array? 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