[Solved] Neat velocity/math problem

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
Locked
User avatar
edward850
Posts: 5902
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

[Solved] Neat velocity/math problem

Post by edward850 »

There is obviously a logical answer to this but I can't think as to what it could be.
I'm spawning an item using [wiki]A_SpawnItemEx[/wiki] using the players momentum. This only works properly if it's using SXF_ABSOLUTEMOMENTUM, and that's fine, but I want to fire off the object at an angle from the player.
So, the idea would be to use the player's current angle, and add that to the objects spawning momentum somehow. So, the question is, how? What equation could be used to do that?

My code, presently, is this:

Code: Select all

A_SpawnItemEx ("Casing", random(1,4), 0, random(2,4)+32, velx, vely, velz, 0, SXF_NOCHECKPOSITION|SXF_ABSOLUTEMOMENTUM)
I would want to add the value to velx/y somehow. Any ideas?
Last edited by edward850 on Sat Mar 10, 2012 11:05 pm, edited 1 time in total.
User avatar
XutaWoo
Posts: 4005
Joined: Sat Dec 30, 2006 4:25 pm
Location: beautiful hills of those who are friends
Contact:

Re: Neat velocity/math problem

Post by XutaWoo »

cos(angle) and sin(angle) for x and y, respectively.

Multiply the force by those and add the result to velx and vely.
User avatar
edward850
Posts: 5902
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Neat velocity/math problem

Post by edward850 »

Either I'm not sure what you are getting at, or I seem to have not explained my problem correctly.
"casing" is to be spawned with the players present momentum. However, the object must always fly away (say, at 3 units of speed) to the right of the player. Using SXF_ABSOLUTEMOMENTUM means I can't just use velx+3 (because that never account for the players angle), and not using it means that the velocity information is thrown off by the players angle.
User avatar
XutaWoo
Posts: 4005
Joined: Sat Dec 30, 2006 4:25 pm
Location: beautiful hills of those who are friends
Contact:

Re: Neat velocity/math problem

Post by XutaWoo »

, velx+(3*cos(angle)), vely+(3*sin(angle)),
User avatar
edward850
Posts: 5902
Joined: Tue Jul 19, 2005 9:06 pm
Location: New Zealand
Contact:

Re: Neat velocity/math problem

Post by edward850 »

Opps, I accidentally put cos instead of sin for valy, and then forgot the save it when I changed it. Silly me.
Thanks for the help.
Locked

Return to “Editing (Archive)”