• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=theJohn;33435391][code]if love.keyboard.isDown("w") then player.x = player.x + math.cos(math.atan2(player.x - love.mouse.getX(), player.y - love.mouse.getY()) + (player.speed * dt)) player.y = player.y + math.sin(math.atan2(player.x - love.mouse.getX(), player.y - love.mouse.getY()) + (player.speed * dt)) end[/code] dt is delta time. It works better now. It moves differently depending on where the mouse is, almost in the opposite direction but not exactly.[/QUOTE] Right. Then you need to reverse player.x and mouse.x and the same the with .y And again, you need to multiply by player speed, not add.
[QUOTE=no-named;33435428]Right. Then you need to reverse player.x and mouse.x and the same the with .y And again, you need to multiply by player speed, not add.[/QUOTE] How's this? [code]if love.keyboard.isDown("w") then player.x = player.x + math.cos(math.atan2(love.mouse.getX() - player.x, love.mouse.getY() - player.y) * (player.speed * dt)) player.y = player.y + math.sin(math.atan2(love.mouse.getX() - player.x, love.mouse.getY() - player.y) * (player.speed * dt)) end[/code] It still doesn't work.
You messed up some parentheses. [code] if love.keyboard.isDown("w") then player.x = player.x + (math.cos(math.atan2(love.mouse.getX() - player.x, love.mouse.getY() - player.y)) * (player.speed * dt)) player.y = player.y + (math.sin(math.atan2(love.mouse.getX() - player.x, love.mouse.getY() - player.y)) * (player.speed * dt)) end [/code] Does this work?
I need help with this simple program. I can't get it to compile. Here is the code: [code] #include <stdio.h> #include <time.h> #include <math.h> int main() { int userNum, resultFactorial; int fact(int ); printf("Please enter a number to find the factorial.\n"); scanf("%d", &userNum); resultFactorial = fact(userNum); printf("The factorial of %d is %d.\n", userNum, resultFactorial); } int fact (int resultFactorial) { int number, enteredNum, endFactorial ; if (number == 0) return 1; else { number = enteredNum * endFactorial (number - 1); return(number); } } [/code] and here is the error I get when I try to compile: [code] recursive.c: In function `fact': recursive.c:26: called object is not a function [/code] Can't figure it out. Also I have to calculate the runtime of the program but we haven't really gone over that in class. She said to do a search online and implement it in the program. I found how to calculate it but not sure how to use it within the program. Help?
[QUOTE=PieClock;33428704]I've been playing with simple platform physics today, however I've got a bit stuck with collisions, which I can't seem to get my head around at all. I've got it working with a bounding box collision, however, this is the problem: [vid]http://puu.sh/9ic0[/vid] Basically, I have no idea how to tell what side of the box the player is colliding with, so I have no way of stopping the player going through the sides, or keeping gravity on when the players hits the sides, and that's what I need help with. I've tried googling around but nothing I find seems to be helping. Nevermind, I'm pretty sure I have what I want now. What I'm doing is checking is the player position in relation to the center of the bounding box. (I have no idea why I didn't think of this, it seems so obvious) Nope. Still can't get this shit to work. It's really fucking hurting my head, I've been fucking with this for hours now. The player will always be left or right of the center, and above or below it, so I still can't tell what side the player is hitting.[/QUOTE] Check if the bottom of the player's bbox is lower than the top of the object's bbox, then check if they're to the left or the right of the edges of the bbox.
[QUOTE=no-named;33435558]You messed up some parentheses. [code] if love.keyboard.isDown("w") then player.x = player.x + (math.cos(math.atan2(love.mouse.getX() - player.x, love.mouse.getY() - player.y)) * (player.speed * dt)) player.y = player.y + (math.sin(math.atan2(love.mouse.getX() - player.x, love.mouse.getY() - player.y)) * (player.speed * dt)) end [/code] Does this work?[/QUOTE] Replaced it with your code. It looks like this now: [url]http://yeyfiles.net/senap/HhXk8Z.mov[/url]
[QUOTE=theJohn;33435883]Replaced it with your code. It looks like this now: [url]http://yeyfiles.net/senap/HhXk8Z.mov[/url][/QUOTE] Oh wow. It's been really long since I've done this. [code] if love.keyboard.isDown("w") then player.x = player.x + (math.cos(math.atan2(love.mouse.getY() - player.y, love.mouse.getX() - player.x)) * (player.speed * dt)) player.y = player.y + (math.sin(math.atan2(love.mouse.getY() - player.y, love.mouse.getX() - player.x)) * (player.speed * dt)) end [/code] Appearently, Y comes before X in that function.
[QUOTE=MrxNine;33435726]I need help with this simple program. I can't get it to compile. Here is the code: [code] #include <stdio.h> #include <time.h> #include <math.h> int main() { int userNum, resultFactorial; int fact(int ); printf("Please enter a number to find the factorial.\n"); scanf("%d", &userNum); resultFactorial = fact(userNum); printf("The factorial of %d is %d.\n", userNum, resultFactorial); } int fact (int resultFactorial) { int number, enteredNum, endFactorial ; if (number == 0) return 1; else { number = enteredNum * endFactorial (number - 1); return(number); } } [/code] and here is the error I get when I try to compile: [code] recursive.c: In function `fact': recursive.c:26: called object is not a function [/code] Can't figure it out. Also I have to calculate the runtime of the program but we haven't really gone over that in class. She said to do a search online and implement it in the program. I found how to calculate it but not sure how to use it within the program. Help?[/QUOTE] [cpp]#include <stdio.h> #include <time.h> #include <math.h> int main() { int userNum, resultFactorial; int fact(int ); printf("Please enter a number to find the factorial.\n"); scanf("%d", &userNum); resultFactorial = fact(userNum); printf("The factorial of %d is %d.\n", userNum, resultFactorial); } int fact(int resultFactorial) { int number, enteredNum, endFactorial; if (number == 0) return 1; else { number = enteredNum * endFactorial * (number - 1); return(number); } }[/cpp] You missed a * also made lots of useless white spaces. EDIT: Actually, wait. What the FUCK are you doing? Ugh. Hold on. I'll fix everything.
[QUOTE=no-named;33436021]Oh wow. It's been really long since I've done this. [code] if love.keyboard.isDown("w") then player.x = player.x + (math.cos(math.atan2(love.mouse.getY() - player.y, love.mouse.getX() - player.x)) * (player.speed * dt)) player.y = player.y + (math.sin(math.atan2(love.mouse.getY() - player.y, love.mouse.getX() - player.x)) * (player.speed * dt)) end [/code] Appearently, Y comes before X in that function.[/QUOTE] Thank you so much for being so patient with me, it finally works! The only problem now is that it starts vibrating when it reaches its destination, but I'll try to fix that by myself.
[QUOTE=MrxNine;33435726]I need help with this simple program. I can't get it to compile. Here is the code: [code] #include <stdio.h> #include <time.h> #include <math.h> int main() { int userNum, resultFactorial; int fact(int ); printf("Please enter a number to find the factorial.\n"); scanf("%d", &userNum); resultFactorial = fact(userNum); printf("The factorial of %d is %d.\n", userNum, resultFactorial); } int fact (int resultFactorial) { int number, enteredNum, endFactorial ; if (number == 0) return 1; else { number = enteredNum * endFactorial (number - 1); return(number); } } [/code] and here is the error I get when I try to compile: [code] recursive.c: In function `fact': recursive.c:26: called object is not a function [/code] [/QUOTE] number = enteredNum * [b]endFactorial (number - 1)[/b]; endFactorial is an int, but you're using it like a function.
[QUOTE=ief014;33436084]number = enteredNum * [b]endFactorial (number - 1)[/b]; endFactorial is an int, but you're using it like a function.[/QUOTE] Also hes checking if number is 0, yet hes never initializing that variable. Among other problems. [editline]25th November 2011[/editline] [QUOTE=MrxNine;33435726]I need help with this simple program. I can't get it to compile. Here is the code: [code] #include <stdio.h> #include <time.h> #include <math.h> int main() { int userNum, resultFactorial; int fact(int ); printf("Please enter a number to find the factorial.\n"); scanf("%d", &userNum); resultFactorial = fact(userNum); printf("The factorial of %d is %d.\n", userNum, resultFactorial); } int fact (int resultFactorial) { int number, enteredNum, endFactorial ; if (number == 0) return 1; else { number = enteredNum * endFactorial (number - 1); return(number); } } [/code] and here is the error I get when I try to compile: [code] recursive.c: In function `fact': recursive.c:26: called object is not a function [/code] Can't figure it out. Also I have to calculate the runtime of the program but we haven't really gone over that in class. She said to do a search online and implement it in the program. I found how to calculate it but not sure how to use it within the program. Help?[/QUOTE] [cpp]int fact(int );[/cpp] What the fuck are you even trying to do? [cpp]int fact (int resultFactorial)[/cpp] You never use that variable in your function. [cpp]int number, enteredNum, endFactorial ; if (number == 0) return 1; else { number = enteredNum * endFactorial (number - 1); return(number); }[/cpp] Here your essentially checking if an uninitialized int is 0(that crashes your app), and if it isn't(it never is), You're multiplying an uninitialized int by what appears to be you using one of your int's as a function. 0_0
Thanks for the help I'll try to make the changes.
[QUOTE=MrxNine;33436273]Thanks for the help I'll try to make the changes.[/QUOTE] No offence, but I have no idea what you were even trying to do? Do you even know how functions work? Look, I'll explain. [cpp]int function(int nX) { return nX * 2; }[/cpp] The "int" is the type your function returns, followed by it's name. The (int nX) means it takes an argument of type int and put's it in an int named nX. { } marks the function block. All variables used in it are destroyed after the function returns. The function returns an int(as declared by the function type(the first int keyword)) in this case, nX multiplied by 2.
Does anyone know how to stop [url=http://yeyfiles.net/senap/QNT3Jr.mov]this[/url]*from happening? [code]if love.keyboard.isDown("w") then player.x = player.x + (math.cos(math.atan2((love.mouse.getY() - 50) - player.y, (love.mouse.getX() - 50) - player.x)) * (player.speed * dt)) player.y = player.y + (math.sin(math.atan2((love.mouse.getY() - 50) - player.y, (love.mouse.getX() - 50) - player.x)) * (player.speed * dt)) end[/code]
.
I still can't understand why you would prototype resultFacto inside of main
[QUOTE=esalaka;33437164]I still can't understand why you would prototype resultFacto inside of main[/QUOTE] I took it out.
[QUOTE=theJohn;33436589]Does anyone know how to stop [URL="http://yeyfiles.net/senap/QNT3Jr.mov"]this[/URL]*from happening? [/quote] Make an if statement that makes sure that the player only moves if distance between mouse and player is larger than X (an unknown number, not the coordinate of anything).
I've never calculated runtime before and what I thought would work isn't. Can someone help me out with calculating the runtime? [code] #include <stdio.h> #include <time.h> int main() { int userNum, factorial; time_t t1, t2; printf("Enter a number to find the factorial.\n"); scanf("%d", &userNum); time(&t1); factorial = resultFactorial(userNum); printf("The factorial of number %d is %d\n", userNum, factorial); time(&t2); printf("It took %f msec. to execute.\n", (t2-t1)/1000); } int resultFactorial (int userNum) { int valueFactorial; if (userNum == 1) return(1); else valueFactorial = userNum * resultFactorial(userNum-1); return (valueFactorial); } [/code] I read gettickcount might work but isn't that for C++? I also read clock_t start might help too.
[QUOTE=theJohn;33433781]I've come up with this original idea for a game &#8212; a top-down zombie shooter! Jokes aside, I have some questions. I'd like the player to be able to move using WASD and the mouse. For that, I need some way to determine the direction in which the player should look to look towards the mouse and then move in that direction when they press W. To this point, I've only made games by just checking if a button is pressed and then move a specific amount of pixels on the coordinate system, but how would I go about to do this? EDIT: I'm making it in LÖVE.[/QUOTE] After you get the angle from the player to the mouse figured out, you can add this for smooth rotation instead of just snapping directly to it. (direction is the angle from player to mouse, both angles are in degrees) [code] sprite_angle=(sprite_angle+(sin(degtorad(direction-sprite_angle))*how_fast_you_want_it_to_spin)); [/code] I don't use love, but it's a fairly simple idea. Also you need to remember to convert between radians and degrees when needed.
[QUOTE=MrxNine;33437666]I've never calculated runtime before and what I thought would work isn't. Can someone help me out with calculating the runtime? [code] #include <stdio.h> #include <time.h> int main() { int userNum, factorial; time_t t1, t2; printf("Enter a number to find the factorial.\n"); scanf("%d", &userNum); time(&t1); factorial = resultFactorial(userNum); printf("The factorial of number %d is %d\n", userNum, factorial); time(&t2); printf("It took %f msec. to execute.\n", (t2-t1)/1000); } int resultFactorial (int userNum) { int valueFactorial; if (userNum == 1) return(1); else valueFactorial = userNum * resultFactorial(userNum-1); return (valueFactorial); } [/code] I read gettickcount might work but isn't that for C++? I also read clock_t start might help too.[/QUOTE] (t2-t1)/1000 isn't a float. It's a long. You need %ld instead of %f. But that still would only show 0ms all the time because of integer division. Learn this [url]http://cplusplus.com/reference/clibrary/ctime/time/[/url] Also, you forgot to prototype your function. Also, stop putting that useless white space after your function name. Also, stop putting an empty newline before else.
[QUOTE=MrxNine;33437666]I've never calculated runtime before and what I thought would work isn't. Can someone help me out with calculating the runtime? [code] #include <stdio.h> #include <time.h> int main() { int userNum, factorial; time_t t1, t2; printf("Enter a number to find the factorial.\n"); scanf("%d", &userNum); time(&t1); factorial = resultFactorial(userNum); printf("The factorial of number %d is %d\n", userNum, factorial); time(&t2); printf("It took %f msec. to execute.\n", (t2-t1)/1000); } int resultFactorial (int userNum) { int valueFactorial; if (userNum == 1) return(1); else valueFactorial = userNum * resultFactorial(userNum-1); return (valueFactorial); } [/code] I read gettickcount might work but isn't that for C++? I also read clock_t start might help too.[/QUOTE] The time() function doesn't have sufficient resolution. It returns an integer number of seconds. If you want milliseconds, you need to use a different function. I have no idea what the function is for Windows.
Actually, I think you meant to do [cpp]int resultFactorial(int userNum) { int valueFactorial; if (userNum == 1) { return(1); } else { valueFactorial = userNum * resultFactorial(userNum-1); return (valueFactorial); } }[/cpp] But what you do works too, in this case. It's a horrible practice tho. if/else takes either a block or a single statement after itself. Thus the last return statement would always be called, since it's not in a block. It doesn't matter, because if you execute the first if statement it returns.
I believe clock() returns the number of ms since the process started.
Does anyone know anything about 3D math? If so, can you help me explain why this is happening with rotation along the X axis? [vid]http://dl.dropbox.com/u/50902102/wierdrotation.mp4[/vid] Here's my code for calculating the camera's rotation: [code] //Target vector direction = glm::vec3(glm::cos(pitch) * glm::sin(yaw),glm::sin(pitch),glm::cos(pitch) * glm::cos(yaw)); targ = glm::vec4(direction,0.0f); //Right vector right = glm::vec3(glm::cos(yaw - 3.14f/2.0f), 0, glm::sin(yaw - 3.14f/2.0f)); //Up vector up = glm::vec4(glm::cross(right, direction),0.0f); //Camera matrix cam = glm::lookAt(glm::vec3(position) , glm::vec3(targ) + glm::vec3(position), glm::vec3(up)); [/code]
[QUOTE=mlbfan560;33449660]Does anyone know anything about 3D math? If so, can you help me explain why this is happening with rotation along the X axis? Here's my code for calculating the camera's rotation: [code] //Target vector direction = glm::vec3(glm::cos(pitch) * glm::sin(yaw),glm::sin(pitch),glm::cos(pitch) * glm::cos(yaw)); targ = glm::vec4(direction,0.0f); //Right vector right = glm::vec3(glm::cos(yaw - 3.14f/2.0f), 0, glm::sin(yaw - 3.14f/2.0f)); //Up vector up = glm::vec4(glm::cross(right, direction),0.0f); //Camera matrix cam = glm::lookAt(glm::vec3(position) , glm::vec3(targ) + glm::vec3(position), glm::vec3(up)); [/code][/QUOTE] You're using two different conventions for 'yaw' in the calculations for 'direction' and 'right'. For 'direction', the x-component is proportional to sin(yaw), while the z-component is proportional to cos(yaw). You do the exact opposite for 'right': x = cos(yaw - pi/2), z = sin(yaw - pi/2) You could drop the pi/2 altogether and make right.x = -cos(yaw) and right.z = sin(yaw), or you could leave the pi/2 in there and adopt the convention you use for 'direction' (right.x = sin(yaw-pi/2), right.z = cos(yaw-pi/2)) It really helps to draw these things, if you're having trouble visualizing it.
Hmm anyone know what kinda trigonometry witch craft I need to calculate the new position of a camera given the rotation of what its looking at is? Ie: [img]http://i.imgur.com/p1fri.png[/img] The camera always looks at the front of the player, if the player rotates the camera rotates with him always keeping the same distance
[QUOTE=Richy19;33450881]Hmm anyone know what kinda trigonometry witch craft I need to calculate the new position of a camera given the rotation of what its looking at is? Ie: [img]http://i.imgur.com/p1fri.png[/img] The camera always looks at the front of the player, if the player rotates the camera rotates with him always keeping the same distance[/QUOTE] Camera.Position = Player.Position + Player.LookVector * Distance Distance is the distance you want the camera to be from the player. LookVector is a normalised vector representing the direction the player is looking in. To calculate that given an angle, just do Player.LookVector = Vector(Cos(Player.Angle), Sin(Player.Angle))
[QUOTE=ROBO_DONUT;33448835]The time() function doesn't have sufficient resolution. It returns an integer number of seconds. If you want milliseconds, you need to use a different function. I have no idea what the function is for Windows.[/QUOTE] time.h's clock() works with milliseconds, however its resolution is usually something around 15ms (Probably enough for what he's doing). [url=http://www.songho.ca/misc/timer/timer.html]This page[/url] explains OS specific timers which have a resolution down in microseconds.
[QUOTE=ief014;33452217]time.h's clock() works with milliseconds, however its resolution is usually something around 15ms (Probably enough for what he's doing). [url=http://www.songho.ca/misc/timer/timer.html]This page[/url] explains OS specific timers which have a resolution down in microseconds.[/QUOTE] The posix solution they give isn't the one I'd use. Modern posix has a function called clock_gettime() which can support resolutions down to nanoseconds (actual resolution is system-dependent) and, if called with CLOCK_MONOTONIC as the first argument, is guaranteed not to ever change abruptly (go backwards if system time changes, etc).
Sorry, you need to Log In to post a reply to this thread.