Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


2D Vector Acceleration: Trying to make an object stay on the center line.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 04 October 2012 - 01:12 AM

I have an object that stays in one place on one of the two inclines, or pipes, however you want to call it. Below shows a top and side view of what's currently going on. In my 2D game, I use the top view for everything. I added the side view so that you may understand the top view's actual design and what it should be like in the game. The game itself uses vectors entirely for all of the entities.

Posted Image

The left side is what the end results should look like, and the right side is what's currently happening im my current build. The right side of the ball may also be on the other side of the incline (pipe), basically meaning that in the game, the ball isn't aligned like the left part of the diagram show above.

Thus, I wanted to add a vector acceleration, so that whenever the ball is off-centered, I can trigger the acceleration, so that the ball moves itself towards the center and align itself.

Posted Image

Problem is, I don't know the ball's acceleration at run-time (the ball could be accelerating outwards, away from the inclines (pipes)), so I would like to ask what vector calculations should I use and how should I use it? Thanks in advance!!

Sponsor:

#2 Freya   Members   -  Reputation: 808

Like
2Likes
Like

Posted 04 October 2012 - 02:00 AM

Suggestion: use some kind of destination point. If the ball has it's destination point in the center between two pipes, you can set acceleration vector as a difference between destination point and current position:
vec acc = (destination - currentPosition).normalied();

Working on a game "Burnt islands".
Dev blog       
"Burnt islands" on Indie DB

#3 tom_mai78101   Members   -  Reputation: 577

Like
0Likes
Like

Posted 04 October 2012 - 04:29 AM

This! Yes! This works. Now, I can continue to flesh out some more incline (pipe) collisions. Thanks! biggrin.png

Code for those curious:

 

float dax = (p.dstRect.left + p.dstRect.width() / 2) - position[0];
float day = (p.dstRect.top + p.dstRect.height() / 2) - position[1];
float dan = FloatMath.sqrt(dax * dax + day * day);
dax /= dan;
this.acceleration[0] -= dax;

Edited by tom_mai78101, 29 December 2012 - 01:41 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS