Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement?
Hmm wierd movement? Hmm wierd movement?
Hmm wierd movement?
Go Back  Xtreme Visual Basic Talk > > > Hmm wierd movement?


Reply
 
Thread Tools Display Modes
  #1  
Old 01-16-2010, 12:11 PM
Tidgney Tidgney is offline
Newcomer
 
Join Date: Jan 2010
Posts: 5
Default Hmm wierd movement?


Hey,

I know there have been topics about this before but i'm still struggling to get my head around it. Im trying to make a game in which an image can rotate which it does already, and when a new direction is pressed i.e. forward or back it moves on that angle its stopped at. So if it was facing 170 degrees it would keep moving along that 170 degrees.

Unsure how to do this :S.

Any help is appreciated

Thanks
Reply With Quote
  #2  
Old 01-16-2010, 12:29 PM
Iceplug's Avatar
IceplugHmm wierd movement? Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

You need to define which direction corresponds to 0 degrees.
Ex: if 0 corresponds to the east or the right direction, then you associate Cos(Angle) with increasing values of X.
X = X + Spd * Cos(Angle)

Next, you define which direction corresponds to 90 degrees (obviously perpendicular to 0 degrees, so it's either up or down).
Ex: If 90 degrees corresponds with south or the down direction, then you associate Sin(Angle) with increasing values of Y.
Y = Y + Spd * Sin(Angle)

Let's say you want 0 to correspond with up, Cos(Angle) will be associated wth decreasing values of Y.
Y = Y - Spd * Cos(Angle)
then, if 90 degrees corresponds to right, Sin(Angle) will be associated with increasing values of X.
X = X + Spd * Sin(Angle)

Once you set these points, your object should move accordingly for all degrees in between.

Also, note that the Sin() and Cos() use Radians and not Degrees, so multiply by Pi / 180 to get degrees.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 01-16-2010, 04:01 PM
Tidgney Tidgney is offline
Newcomer
 
Join Date: Jan 2010
Posts: 5
Default

Hey,

Thankyou for the response. I have tried to use the code given, but sometimes it goes in the correct direction sometimes it doesnt. It moves at all different angles so unsure what the problem is, i used

Xcorner = Xcorner + Sin(angle)
Ycorner = Ycorner + Cos(angle)

Player2.Left = Xcorner + 1
Player2.Top = Ycorner + 1

Within a timer, Angle * pi / 180 is within the rotation part of my program do i need that in this aswell as the angle variable is a global variable. Or what else is needed to make it move in the correct direction the same as the angle.

As well my rotation bumps slightly as if its hitting something or hitting the edge of the picture box, how is this solved aswell (This is a tiny thing though compared to the moving)

Thanks again for the help so far, any more is totally appreciated!!!
Reply With Quote
  #4  
Old 01-16-2010, 04:12 PM
Tidgney Tidgney is offline
Newcomer
 
Join Date: Jan 2010
Posts: 5
Default

I did the + without the times because the speed is 1, so doesnt effect the result of the sin or cos i think?
Reply With Quote
  #5  
Old 01-16-2010, 05:39 PM
Tidgney Tidgney is offline
Newcomer
 
Join Date: Jan 2010
Posts: 5
Default

Hi again,

Treble posting allowed ?? unsure but just incase poeple read above and now new info. Was right to add the additional

If angle = 0 Then
Player.Left = Player.Left + 1
Else
Xcorner = Xcorner + Sin(angle * PI / 180)
Ycorner = Ycorner + Cos(angle * PI / 180)

Player2.Left = Xcorner + 1
Player2.Top = Ycorner + 1

But now i just have to work out why the tank starts off fine, but the angle is of from the picture . Tank starts of heading forward then i turn, it turns so many degrees and moves forward in the angle which is 180 degrees off, but no matter what side it moves 180 degrees so know that it works, just moves forwards on the track side rather than gun side :P.

edit:

Turned out i just had sin and cos's wrong way round with -'s to managed to get it working.

If angle = 0 Then
Player.Left = Player.Left + 1
Else
Xcorner = Xcorner + Cos(angle * PI / 180)
Ycorner = Ycorner + -Sin(angle * PI / 180)

Player2.Left = Xcorner + 2
Player2.Top = Ycorner + 2
End If

Thankyou soso much for that .

Last edited by Tidgney; 01-16-2010 at 05:44 PM.
Reply With Quote
  #6  
Old 01-17-2010, 09:32 AM
Tidgney Tidgney is offline
Newcomer
 
Join Date: Jan 2010
Posts: 5
Default

Hey,

I've hit another problem.

I want the computer player (I.e. opposite vehicle) to move towards the target so that you have to kill it, but it will move towards your vehicle constantly throughout the game unless its dead Im unsure how you do this.

I know that its something to do with targets position and current position

Only thing i can think of is doing something like the following

Target.left (Which is x co-ordinate i think) - Enemy.left = distance
Same for the Y axis
This gives distance needed and height needed, but how to make it move at a steady pace towards the target is where im struggling.

I have written this it follows but it slows down and stops near it, is there something im missing??

y = Ycorner - enemy.Top
X = Xcorner - enemy.Left

enemy.Left = enemy.Left + X / 200
enemy.Top = enemy.Top + y / 200

Last edited by Tidgney; 01-17-2010 at 09:53 AM.
Reply With Quote
  #7  
Old 01-17-2010, 09:43 PM
Iceplug's Avatar
IceplugHmm wierd movement? Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: Iowa, USA
Posts: 16,583
Default

Using Pythagorean stuff to make an object move from one point to another.
RPG Movment/heading help
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement? Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement? Hmm wierd movement?
Hmm wierd movement?
Hmm wierd movement?
 
Hmm wierd movement?
Hmm wierd movement?
 
-->