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 /
  • Help Room /
avatar image
0
Question by cchrismicrowave · Feb 01 at 04:08 AM · 2d gameprojectile

Getting projectile to leave marks at where its hit, for example different spot of a building of a 2D game?

Hi everyone, I am a total beginner to game making and programming, I am trying to make a gameplay about shooting things onto building and leaving marks of where it landed in a 2D Zelda-liked game, for example, the player is able to shot the projectile and leave marks on door, windows, walls, different parts of the building based on the distance between the player and the building.

My very naive approach is to record the projectile bornTime, entryTime (where the project touches the building box collider), and determine a value of airBorneTime,, so that I get the travelTime (that allows the projectile 'travels' within the building box collider, let say 0.1s ) and after the travelTime, I would turn off the isTrigger to make the projectile stay in place,

BUT after I spent a couple of days to make the code running, it didnt work, instead, the projectile just bounces out of the boxCollider area.

I am wondering if anyone could point me to a better direction/approach? I am very new to programming too, this was my best shot so far help please!! thank you so much!

here is my clunky code (for some reason the projectile is called boba) public class Boba : MonoBehaviour { public float speed; public Rigidbody2D myRigidbody;

     public float lifetime;
     private float lifetimeSeconds;
 
     private Animator animator;
     public int statesNumber;
 
     private float bornTime;
     private float enterTime;
     private float travelTime;
     public float airBorneTime;
 
     Collider2D myCollider;
 
     void Start()
     {
         myRigidbody = GetComponent<Rigidbody2D>();
         lifetimeSeconds = lifetime;
 
         animator = GetComponent<Animator>();
         animator.SetBool("isLanded", false);
 
         bornTime = Time.time;
         
     }
 
     public void Setup(Vector2 velocity, Vector3 direction)
     {
         myRigidbody.velocity = velocity.normalized * speed;
         transform.rotation = Quaternion.Euler(direction);
 
         myRigidbody.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
         myCollider = GetComponent<Collider2D>();
     }
 
     private void Update()
     {
         lifetimeSeconds -= Time.deltaTime;
         if (lifetimeSeconds <= 0)
         {
             Destroy(this.gameObject);
             
         }
     }
 
     private void OnTriggerEnter2D(Collider2D collision)
     {
         enterTime = Time.time;
     }
 
     private void OnTriggerStay2D(Collider2D collision)
     {
         
         StartCoroutine(bobaEnterCollider());
         bobaEnterCollider();
        
     }
 
 
     private IEnumerator bobaEnterCollider()
     {
         travelTime =  airBorneTime - (enterTime - bornTime);
 
         yield return new WaitForSeconds(travelTime);
 
         myCollider.isTrigger = false;   
         animator.SetBool("isLanded", true);
         animator.SetInteger("bobaLandedRandom", Random.Range(0, statesNumber));
     }
 
     
 
 }
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

0 Replies

· Add your reply
  • Sort: 

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

221 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

Related Questions

Rotate projectile sprite in the direction it is flying (like an arrow) 2D. 1 Answer

Firing a projectile change the direction of the other projectiles. 1 Answer

make an enemy spell move towards player 1 Answer

Firing Projectile on path,Firing Rockets on path 0 Answers

How do you make one game object follow the shape of another game object? 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