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 Rasp1977 · Jul 07, 2012 at 07:25 PM · rigidbodyvector3velocitypong

How to set velocity to a previouse value

Hi all

I am making a small pong style game and have a problem when the ball hit the paddle at the bottom it will some times slow down. Guessing it's when I move it as the ball is hitting it.

I have stored the last correct velocity in a vector3 and want to set it if the ball speed drop below that value.

If I just set the velocity of the rigidbody on my ball to my saved velocity, it also changes the direction of the ball to what it was when I stored it.

How do I keep my ball direction, and only set the velocity of the ball to my stored vector3?

Thx Rasmus

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

1 Reply

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

Answer by rutter · Jul 07, 2012 at 10:53 PM

How do I keep my ball direction, and only set the velocity of the ball to my stored vector3?

Velocity represents both speed and direction, which means you are implicitly assigning a direction when you assign velocity.

If I had to guess, you actually want to keep the old speed, but move in the current direction? If so, some quick vector multiplication can achieve that:

 //produce a new velocity vector:
 //  - use same magnitude (speed) as current velocity
 //  - use previous direction
 rigidbody.velocity = rigidbody.velocity.magnitude * lastVelocity.normalized;
Comment
Add comment · Show 4 · 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 Rasp1977 · Jul 08, 2012 at 09:16 AM 0
Share

I have already tried this and the problem is that it makes the ball change direction. I only want to add force to the ball, not change direction.

Example : Ball hits the paddle and slows down, it's going in the right direction, but to slow.

I detect this be looking at it's magnitude. I then want to keep the direction the ball is going in now, but set something on the rigidbody that will increase it's magnitude back to the original value.

$$anonymous$$y game works fine 95% of the time, but not if I move the paddle really fast to catch a ball, then it happens.

avatar image whydoidoit · Jul 08, 2012 at 09:33 AM 1
Share

Perhaps you should try rigidbody.velocity = rigidbody.velocity.normalized * $$anonymous$$imumSpeed

avatar image Rasp1977 · Jul 08, 2012 at 10:20 AM 0
Share

That was exactly what I needed, thx.

Do I just accept the entire answer or can I only except whydoidoit's answer as it's the correct one?

avatar image whydoidoit · Jul 08, 2012 at 10:23 AM 0
Share

Just accept the whole answer. I was just popping in to help :)

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

Comparing rigidbody speeds 1 Answer

Rigidbodies with fixed joint connection rotate instead of forward/back 1 Answer

Error on 'velocity = [Vector3].normalized'? 1 Answer

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

2d game - looking toward velocity for rigidbody player 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