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 tokenshi · Sep 01, 2011 at 03:00 PM · movement2d-gameplaypingpong

2D Object Movement, PingPong issues

I'm working on a Top-Down 2D, Raiden Style Shooter. The player Ship basically stays withing a clamped range, and doesn't move through game space. Enemy objects spawn off the screen, then move down to a random 'near' range before they start firing/moving.

I have it set up to have the enemies pingpong when they hit the near range, however, for some reason the enemies jump position at the start of it, leading to a choppy transition between their approach and the start of their patterns. Here's the code - tell me what you think is wrong please.

 enum enemyRange {Far =0, Near =1}
 var positionSet: boolean;
 //var player : Transform;
 var initialPosition : Vector3;
 var enemyWiggle : Vector2;
 var nearRange : float;
 static var eRange = enemyRange.Far;
 
 var enemySpeed : float;
 function Awake() {
 nearRange = Random.Range(3,4);
 }
 function Start () {
 
 }
 function Update () {
 if (!positionSet) {
 CheckStatus();
 }
 if (positionSet) {
 
 EnemyPong();
 }
 
 //Initiates the range testing
 switch (eRange) {
 
 case enemyRange.Near:
 break;
 
 case enemyRange.Far:
 
 transform.Translate(-Vector3.forward*(enemySpeed)*Time.deltaTime);
 break;
 
 }
 }
 function CheckStatus()
 
 {
 if ((transform.position.z > nearRange)&&(!positionSet)){
 eRange = enemyRange.Far;
 positionSet = false;
 }
 else if (((transform.position.z <= nearRange) && (eRange==enemyRange.Far)&&(!positionSet))){
 //print (transform.position.z + "should be where it pings to");
 positionSet = true;
 
 eRange = enemyRange.Near;
 initialPosition = transform.position;
 
 
 
 }
 }
 function EnemyPong() {
 transform.position.x = Mathf.Clamp(initialPosition.x + Mathf.PingPong(Time.time * enemySpeed, enemyWiggle.x),-4,4);
 transform.position.z = Mathf.Clamp(initialPosition.z + Mathf.PingPong(Time.time * enemySpeed, enemyWiggle.y), 1,49);
 
 }
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

2 People are following this question.

avatar image avatar image

Related Questions

Creating a 2D Movement Grid 0 Answers

Need air control for 2D-Game 0 Answers

How do you make a 2D char. dodge and move to his original spot? 0 Answers

Issues with Player Input System & 2D,Issues with Player Input system & 2D Movement 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 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