Jump to content
  • Advertisement
Sign in to follow this  

Mesh Object movment

This topic is 4113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im using DirectX and C# working on a networked game, what I am trying to do is as a player shoots the user input will send a packet to the server the packet information is type of mesh, location Vector, and direction Vector on the server I'm caculating collision and updating the clients with the new position all im doing is position += direction * .8f; this works great at position Vector 0,0,0 but if the player moves then shoots its not working right, its moving to fast and out of range. any help would be great!!!!

Share this post

Link to post
Share on other sites
More information is needed. What doesn't work? When you move the player, the player doesn't respond properly or the bullet flies improperly? Can you give a little more detail? It's kind of hard to picture what exactly is happening.

Share this post

Link to post
Share on other sites
sorry about the lack of info

when the player position moves and then fires again, the bullet is not showing up at the current players position, let me show you what I mean

this is the position packet data before the player is moved of the bullet

position Vector3(0.001653842, 0.01151682, 0.7999153)
position Vector3(0.003307683,0.02303363,1.599831)
position Vector3(38,0.004961525,0.03455045,2.399746)

nice smooth movment in a stright line

after the player is moved

Position Vector3(8.304617,-0.01448199,-10.01892)
Position Vector3(12.21811,-0.02896398,-14.08715)
Position Vector3(16.13161,-0.04344597,-18.15538)

both are using position += direction * .8f

it is clearly a math issue Im just not sure how to go about fixing it.
I just want the bullets to go in a stright line from the players current position and direction and .8f would be the volicity right?

Share this post

Link to post
Share on other sites
It depends on how you want to define your velocity. The basic formula is:
delta_pos = vel*delta_time.
So in your case, your velocity is the direction variable, and 0.8 is your time difference. If this occurs every frame, and your direction is a unit vector (it should be, and this may be your problem), then you are moving the bullet at a max of .8 units per frame when the direction is aligned with the axis, which I suspect is really fast.

You need to be sure that the direction variable is normalized (has a magnitude of 1). If it is normalized, and you move but still have other issues, you should at least see the bullet moving at the same speed.

Also consider implementing each component of the equation. Calculate delta_time each frame (this frame's time minus last frame's time, use a performance timer for best results, or just use timegettime for now to get going). Normalize the direction vector, then multiply it by a magnitude, where the magnitude is your velocity. i.e. Direction is straight down X at 100 units/sec, and time difference is 0.033 seconds, so:
pos += direction_norm*100*0.033.

Hope that helps.

Share this post

Link to post
Share on other sites
this is still not working and makes no sence.

I have used this before andseems to me it worked fine

from what I can tell when ever the players position is in the -Z
but is looking along the +z like
positionVector3(0, 0, -10.0f)

directionVector3(0, 0, -9.0f)

the bullet travels behind the player along the -z

if you move to the left/right it goes just crazy

any other suggestions?

Share this post

Link to post
Share on other sites
I had to something like this with my camera. I accomplished this with a simple function:

Vector3 direction = unit vector for the direction of travel.
float magnitude = the rate of travel.
position.Add(direction); //position would be the object you are moving obviously.

This is probably the easiest way to do it. It's really important that your direction vector be a normalized/unit vector.

Share this post

Link to post
Share on other sites
tried that and still same thing happening, let me get this right to Normalize
a vector3 you just go


it has to be something to do with the direction im using,
the game uses a first person camera so im using the camera lookAt to determine
the direction, now if the player position is Vector3(0,0,-10) and the player is looking forward on the z the lookAt will be Vector3(0,0,-9). now when you add two -numbers they get bigger right?

so position(0,0,-10) += direction(0,0,-9) * time;

with this said the object will keep moving along the -z if the lookAt <= -1.0f
so how can I fix this problem?

is there something else I should do to that lookAt vector before sending it?

Share this post

Link to post
Share on other sites
No, your direction vector should be (0, 0, -1). The x,y,z values should fall between -1 and 1. Always.

Say you want your object to move by 0.5f every time you press up. Your direction vector is (0, 0, -1), therefore it points along the -z axis. The object's position is (0, 0, -10);

magnitude = direction * 0.5f = (0, 0, -0.5);
position + magnitude = (0, 0, -9.5);

That should be the outcome. I don't know what else i could tell you because I am using that exact calculation and it works flawlessly for me. If it's still not working, try doing this with just the bullet on a keystroke. Also trace each time the bullet moves to see how the position progresses. Then see what happens when you add the player position in.

Share this post

Link to post
Share on other sites
that was/is my problem, im using the firstperson camera in the sampleFramework and when you move the camera backwords the camera lookAt stays 1 vector in front of the position or eye of the camera
so I will change the vector3 to either a +1 or -1 and see if that works,

now how about the x and y are they going to go above +1 or -1 on the x or y?

thanks for your help

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!