You should calculate a target position from sin() and cos() and the object's position, and then just applyForce from that.
Hi there folks (what a cheesey way to start a post). Can anyone help me solve my little conundrum i seem to have created? What im wanting to do is make a prop e.g a 1 x 1 phx prop plate orbit another prop. Ive been trying to use applyForce() and ive managed to get a 1 x 1 x 1 phx cube to travel round in circles similar to how my orbit should be. (out of luck most likely :P). My code so far is below:
ive read through the e2 wiki and read through some of the tutorials on here but whatever i try it doesnt seem to want to work. im guessing what im wanting will be similar to the way people are making props orbit their player but im just not too sure how to impliment itCode:@persist Timer X Y Z runOnTick(1) Timer = Timer+1 X=(sin(Timer*2)*200) Y=(cos(Timer*2)*200) applyForce(vec(X,Y,Z))
any helps appreciated, cheers![]()
You should calculate a target position from sin() and cos() and the object's position, and then just applyForce from that.
okay so if im doing this right.. ive ended up with a vector from the cos() and sin() and ive also ended up with another vector for the stationary object. What should i be doing with these two vectors now? im assumed id add them together to produce a single vector to feed into the applyForce() ?
FYI: you didn't define Z
Also: no need to persist X, Y, or Z
and you can write Timer++ instead of Timer =Timer+1
There we goCode:@persist Timer runOnTick(1) Timer = Timer++ X=(sin(Timer*2)*200) Y=(cos(Timer*2)*200) Z=20 applyForce(vec(X,Y,Z))still can anyone help me to get the orbit to actually orbit an object and not just orbit a random spot?
i tried
X1, Y1 & Z1 being variables input from a gps device.. im really not sure how to go about it.Code:applyForce(vec(X,Y,Z) + vec(X1,Y1,Z1))
Well, applyForce(V) acts on this chip itself, which I'm guessing is not what you want. You need to specify the entity to apply force to, with E:applyForce(V). Try this:
[highlight=e2]@persist CentreProp:entity OrbitProp:entity
if (first() | duped()) {
runOnTick(1)
# define CentreProp and Orbit Prop here
# it depends on how you want to find them
}
T = curtime()
X = R * cos(T / S)
Y = R * sin(T / S)
OrbitProp:applyForce(CentreProp:pos() + vec(X,Y,0))
[/highlight]
R is the radius of the orbit, and S is the angular speed you want, in degrees per second. Both should be replaced in the code, since they don't need to be variables.
Other big changes I made:
1) Sine and cosine were flipped. X should correspond to cosine.
2) Adding entity variables for the two props. You need these in order to tell the chip what to apply force to.
3) Modifying "vec(X,Y,Z) + vec(X1,Y1,Z1)" to "vec(X,Y,Z) + CentreProp:pos()" which is essentially the same thing. Every prop E has a built-in GPS that is accessed by E:pos().
4) Used curtime() instead of incrementing a timer variable. curtime() returns the number of seconds since the server started.
5) Put some things in a conditional at the top. These are for things that only need to be run on the first execution. In this case, defining the props and telling the chip to run on every tick.
Why thankyouyour helps much appreciated, and thanks for the explanation made the whole world of diffference
have a cookie![]()
![]()
you forgot stabilising deltas... :S...
orCode:@persist CentreProp:entity OrbitProp:entity if (first() | duped()) { runOnTick(1) # define CentreProp and Orbit Prop here # it depends on how you want to find them } T = curtime() X = R * cos(T / S) Y = R * sin(T / S) OrbitProp:applyForce(CentreProp:pos() + vec(X,Y,0) - $ OrbitProp:pos() * G) #Make G a number between 1 and 5. its a trial and error thing because of intervals and what not.
Code:@persist CentreProp:entity OrbitProp:entity if (first() | duped()) { runOnTick(1) # define CentreProp and Orbit Prop here # it depends on how you want to find them } T = curtime() X = R * cos(T / S) Y = R * sin(T / S) OrbitProp:applyForce(CentreProp:pos() + vec(X,Y,0) - OrbitProp:velocity() * G) #Make G a number between 0.5 and 3.
Last edited by Aaron[The1]; 07-28-2009 at 04:41 PM.
just too good for E2...
Aaron, the $ cant have a space between it and the variable. And it's E:vel() not E:velocity().
And that's still not right. You have to also subtract the orbiting props' position.
The basic formula you use is
((Target - Current)*somemultiplier - ChangeInCurrent*anothermultiplier)*Evenanotherifyo ulike
Target is CentrePropos() + vec(X,Y,0)
Current is the current position of the orbiting prop, OrbitPropos()
ChangeInCurrent is OrbitProp:vel()
im having even more problems..
so ive defined the centre prop & orbit prop however the orbit prop likes to fly away into the sky box, its got a mind of its ownCode:@persist CentreProp:entity OrbitProp:entity if (first() | duped()) { runOnTick(1) CentreProp = entity():isWeldedTo() findByModel("models/props_phx/construct/metal_plate1.mdl") OrbitProp = find() } T = curtime() R = 100 S = 2 X = R * cos(T / S) Y = R * sin(T / S) OrbitProp:applyForce(CentreProp:pos() + vec(X,Y,0))
oh and before stabalizing gets mentioned.. im planning to work on that after i get it working
Edit: Tried the following code to no avail, it just sits there and floatsThe multipliers are probably a bit dodgey too seen as ive not been able to test them out. Anyone figure out whats wrong with it?
Code:@persist CentreProp:entity OrbitProp:entity if (first() | duped()) { runOnTick(1) CentreProp = entity():isWeldedTo() findByModel("models/props_borealis/bluebarrel001.mdl") OrbitProp = find() } T = curtime() R = 100 S = 2 X = R * cos(T / S) Y = R * sin(T / S) Z = 500000 OrbitProp:applyForce((CentreProp:pos()+vec(X,Y,Z) - (OrbitProp:pos()*10 - OrbitProp:vel()*10))
Last edited by darkpasts; 07-28-2009 at 06:39 PM.
Bookmarks