Help Wanted

An Issue – Ereon

Ereon

Member

Posts: 1018
From: Ohio, United States
Registered: 04-12-2005

Ok, here's the skinny. My baddies have a bad habit of getting too close together. To ameliorate this problem, I'm trying to come up with an equation to displace them away from each other by a certain distance (represetned by the short blue line) to a point on the green circle that is on the same angle. So, essentially, I'm trying to push the repelled character outwards to the green circle from its position on the black circle, while still keeping it at the same relative angle from the repeller. I know there's got to be some kind of triginometric solution to this, but I haven't found it yet, and don't anticipate doing so for at least another several hours of work :P . What I need is probably going to end up being something with sine and cosine, with an adjustable radius (which I don't think you can do with vanilla unit circle trig formulas, which is all I know). If I can just set the radius to a variable I can make it work, but I can't even begin to find anything that looks feasible. Thanks in advance for your help.

------------------

The time for speaking comes rarely, the time for being never departs.
George Macdonald

MastaLlama

Member

Posts: 671
From: Houston, TX USA
Registered: 08-10-2005
Do you have the x,y coords of the repeller? If so you may not need too much trig.
kenman

Member

Posts: 518
From: Janesville WI
Registered: 08-31-2006
Your thinking to much, I had this problem in a game I created once

some logic like

if x1 is within 2 of x2 AND
y1 is within 2 of y2 then
This turn move away from each other (

This will prevent clumping of your dudes

Ereon

Member

Posts: 1018
From: Ohio, United States
Registered: 04-12-2005
I have the coords for both guys, I just need the new, repelled coords. The move away thing would be great, but I want the characters to remain pointed toward the player, I don't want them to face away, just adjust. If I could just tell them to walk away from each other it would be fine, but I want something that will work in the background and subtlety shift as the game goes along.

------------------

The time for speaking comes rarely, the time for being never departs.
George Macdonald

InsanePoet

Member

Posts: 638
From: Vermont, USA
Registered: 03-12-2003

Problem solved.

(it's the symbol for the male gender)

------------------
"I find myself a desire which no experience in this world can satisfy, the most probable explanation is that I was made for another world!"
-C. S. Lewis

kenman

Member

Posts: 518
From: Janesville WI
Registered: 08-31-2006
For example troops can walk backwards or sidways slower, if they bunch think about that as a move.
Ereon

Member

Posts: 1018
From: Ohio, United States
Registered: 04-12-2005
Kenman: I understand what you're saying, the only problem is that solution is about 4-5 commands long and each requires a fresh computation inside the engine. I'm searching for something more elegant. I think I can knock it down to two command, if I can just find a method to get the repelled character's angle relative to the repelling character's. If I can get that angle I can make it work.

------------------

The time for speaking comes rarely, the time for being never departs.
George Macdonald

samw3

Member

Posts: 542
From: Toccoa, GA, USA
Registered: 08-15-2006
a unit sin and/or cos is for a radius of 1. To get the coordinates at multiple radii, just multiply the unit radius by the actual radius.

For instance baddy1 is at a radius of 5 from baddy2. You want baddy1 to move to a radius of 7. Mutiply the sin/cos of the angle by 7. that will give you the new coords.

However, personally, I think ken's solution is elegant in its simplicity and 4 boolean operations will execute a LOT faster than sin/cos calculations.

Also, there may be a middle ground by using dot-products, but I'm a bit rusty on my vector math. dartsman could really help you here. Maybe read the Vision-BB thread that M^2 started. Its similar I think.

God Bless!
------------------
Sam Washburn

[This message has been edited by samw3 (edited June 21, 2007).]

MastaLlama

Member

Posts: 671
From: Houston, TX USA
Registered: 08-10-2005
quote:
Problem solved.

(it's the symbol for the male gender)


Nice. LOL

here's some messy psuedocode


x1 = 5
y1 = 7

if x2 < x1+3 then
x1=x-1
end if
if y2 < y1+3 then
y1=y-1
end if

Very simplistic and just an example but you get the idea. Also, change the x,y coords of an entity shouldn't have to mean you change the direction said entity faces. ...just a thought

[This message has been edited by mastallama (edited June 21, 2007).]