I am trying to move a player in direction angle by speed. I need to use trigonometric functions in order to calculate this. Can anyone help me discover how to do this?

if (playerB.up == true) {
            (playerB.speed)+=((Delta*ballspeed)/1000);
            }
        if (playerB.down == true) {
            (playerB.speed)-=((Delta*ballspeed)/1000);
            }
        if (playerB.left == true) {
            (playerB.angle)-=((Delta*ballspeed)/1000);
        }
        if (playerB.right == true) {
            (playerB.angle)+=((Delta*ballspeed)/1000);
        }
		//move player in direction angle by speed

Recommended Answers

All 2 Replies

>> I am trying to move a player in direction angle by speed

I am kind of hesitant of what you mean exactly by that, can you explain?

Why don't you do it with vectors? it's alot less work.
Just define a vector with a specified length (your speed) and use a rotation matrix to rotate it the amout of degrees.
Then add each component of the vector to your position.

Just google on the terms vector and rotation matrix and read wikipedia. that should be enough.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.