generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Direction data in scripts

Previous Thread :: Next Thread 
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
31 Mar 2012 10:12 AM
I have a 2d game, and I want something to be able to take something and be able to know what direction it should be going in. Now obviously I can just send something the angle of rotation in its constructor, but then how would it know which way it's supposed to be going in? I don't want it just to go in forwards, backwards, left, right, etc, I need it go be able to go everywhere.
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
31 Mar 2012 10:21 AM
Math vectors?
Report Abuse
IAmNotWise is not online. IAmNotWise
Joined: 28 Jul 2011
Total Posts: 1418
31 Mar 2012 10:23 AM
[ Content Deleted ]
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 10:43 AM
You shouldn't be using angles and trig at all if possible. Vectors are what you need. And they're really easy to manipulate.

Of course you will still need angles and trig functions in cases where you need angular velocity and stuff like that, but you should convert to vectors whenever possible.
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
31 Mar 2012 10:50 AM
So how would convert the stuff to vectors - remember it's not just 4 directions they need to be facing, it's any direction at all.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 10:56 AM
Say the position of your thing is vector a.
And the position of where it wants to face towards is vector b.

c = b - a is the vector pointing towards b from a

c/|c| is the unit vector facing that direction.

|c| means vector length or magnitude, which is just sqrt(c.x^2 + c.y^2)

Divide it by its length and get a unit vector, a vector with the length of one.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
31 Mar 2012 11:02 AM
[ Content Deleted ]
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 11:04 AM
I'm not exactly sure what he's asking, but that was my guess. If he wants an object to rotate towards another over time and then start moving, you'll have to use angles, yes.
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
31 Mar 2012 11:11 AM
What should happen:

Generate object facing in any random direct
Object starts moving forwards in the direction it is facing
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 11:15 AM
Then you could just create a random vector, I suppose.
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
31 Mar 2012 11:16 AM
you need an unit vector that points towards that direction k?
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
31 Mar 2012 11:19 AM
[ Content Deleted ]
Report Abuse
IAmNotWise is not online. IAmNotWise
Joined: 28 Jul 2011
Total Posts: 1418
31 Mar 2012 11:21 AM
[ Content Deleted ]
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 11:22 AM
@Oysi, but since he said he wants a random direction you can just generate a random vector and it unit length. There may not be completely random distribution,especially in a rectangular map, but that shouldn't be much of an issue.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 11:23 AM
*make it of unit length
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
31 Mar 2012 11:23 AM
[ Content Deleted ]
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
31 Mar 2012 11:26 AM
[ Content Deleted ]
Report Abuse
Brandonhare is not online. Brandonhare
Joined: 02 May 2007
Total Posts: 11005
31 Mar 2012 11:29 AM
I usually do this:

angle = math.atan2(pointToFaceY-posY,pointToFaceX-posX)
--makes it face pointToFace

Now to make it move in that direction:

velocity = 10
posX = posX + velocity * math.cos(rotation)
posY = posY + velocity * math.sin(rotation)
-- this should make it move 'velocity' units in the direction it's facing. I may have mixed up sin and cos.

Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
31 Mar 2012 11:44 AM
Not a random direction, but a specified direction that I can generate easi -

screw it, here is the code I have just to demonstrate:

void Mawbane::e(){
std::stringstream ss;
for(int i=1;i<4;i++){
StraightProj* proj = new StraightProj("mawbane_e.png",DIRECTION);
ss << i;

}
}
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 11:46 AM
Then use vectors?

Gotta implement a nice vector class with overloaded operators if you want it to be simple when doing vector operations.
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
31 Mar 2012 12:02 PM
I have an sfml vector class. But, as I said, how would I make the vectors in every direction?>
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
31 Mar 2012 12:05 PM
You won't, you said yourself you already know what direction you want them to go. Just convert that direction (whatever units you have it in) to a unit vector.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
31 Mar 2012 12:07 PM
[ Content Deleted ]
Report Abuse
pighead10 is not online. pighead10
Joined: 03 May 2009
Total Posts: 10341
31 Mar 2012 01:27 PM
@Oysi

Sorry, I meant to say I hadn't actually read them because I was typing while waiting for something.
Report Abuse
miloguy is not online. miloguy
Joined: 19 Dec 2009
Total Posts: 7702
31 Mar 2012 03:31 PM
learn2simple trig?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image