Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums Math question
 User Name Remember Me? Password
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 07-07-2012, 04:05 AM #1 colfaxrev bit chez fr.digital house     Join Date: Mar 2006 Location: Los Angeles Posts: 688 Math question this is for physics in a game. I am using box 2d engine so the physics is already handled. please look at my attachment pic, it explains it quite simply basically i need to split x velocity into x and y velocity when trying to walk up a slope, and for some reason i can't figure out the right formula any help would be greatly appreciated! Attached Thumbnails   __________________ Music is life
 07-07-2012, 01:20 PM #2 ASWC Super Moderator     Join Date: Dec 2007 Location: Greenville, SC Posts: 6,528 Reduce the gravity or reduce the friction on both or apply a friction joint. __________________ aswebcreations Super Duper!
 07-08-2012, 05:40 AM #3 colfaxrev bit chez fr.digital house     Join Date: Mar 2006 Location: Los Angeles Posts: 688 reducing gravity isn't an option because the feeling of how jumps works depends on that, the friction must stay cause some blocks need to be icy and slick and others need to ahve more friction im close to the solution though if i have an x velocity of 10 and the hill is at a -45 degree angle then x velocity should be 5 and y velocity should be -5 if it were a 90 degree angle (a wall) it would be x velocity 0 and y velocity -10 obviously i won't make walls do that but thats the ratio so its a ratio, just trying to figure out how to spell it out in a formula __________________ Music is life
 07-08-2012, 06:02 AM #4 santanoa Dual Screen Empowered     Join Date: Jul 2010 Location: Israel Posts: 258 isn't it vx = vcos(theta) vy = vsin(theta) where vx is your x velocity, vy is your y velocity and v is your absolute velocity or velocity you want to distribute over x and y. theta is your angle. That's what I learned in Physics class
 07-08-2012, 07:18 AM #5 colfaxrev bit chez fr.digital house     Join Date: Mar 2006 Location: Los Angeles Posts: 688 thanks for that answer! I think that looks about right although i did just get this to work Code: ```private function _onMouseWheel(event:MouseEvent):void { _floorSprite.rotation += event.delta; var radians:Number = deg2rad(_floorSprite.rotation); var radians90DegreeAngle:Number = deg2rad(90); var xVel:Number = 10; var yVel:Number = 0; trace('-----------------------'); trace('_floorSprite.rotation[' + _floorSprite.rotation + '] radians[' + radians + ']'); trace('b xVel[' + xVel + ']'); trace('b yVel[' + yVel + ']'); trace('transform to XY velocity'); //var angleRatio:Number = -_floorSprite.rotation / 90; var angleRatio:Number = -radians / radians90DegreeAngle; trace('angleRatio[' + angleRatio + ']'); if (angleRatio >= 0) { //trace('uphill'); yVel = -((xVel * angleRatio)); xVel = xVel + yVel; } else if (angleRatio < 0) { //trace('downhill'); yVel = -((xVel * angleRatio)); xVel = xVel - yVel; } trace('a xVel[' + xVel + ']'); trace('a yVel[' + yVel + ']'); }``` __________________ Music is life
07-08-2012, 07:26 AM   #6
colfaxrev
bit chez fr.digital house

Join Date: Mar 2006
Location: Los Angeles
Posts: 688

Quote:
 Originally Posted by santanoa isn't it vx = vcos(theta) vy = vsin(theta) where vx is your x velocity, vy is your y velocity and v is your absolute velocity or velocity you want to distribute over x and y. theta is your angle. That's what I learned in Physics class
that seems close but it wasn't giving me the right values im sure if that formula was correct it would run a lot faster than mine though
__________________
Music is life

 07-08-2012, 07:31 AM #7 colfaxrev bit chez fr.digital house     Join Date: Mar 2006 Location: Los Angeles Posts: 688 Code: ```private function _onMouseWheel(event:MouseEvent):void { _floorSprite.rotation += event.delta; var velocity:Number = 10; var theta:Number = -deg2rad(_floorSprite.rotation); var vx:Number = velocity * Math.cos(theta); var vy:Number = velocity * Math.sin(theta); trace('vx[' + vx + ']'); trace('vy[' + vy + ']'); }``` these numbers aren't quite right, do i have that right? __________________ Music is life
 07-08-2012, 07:36 AM #8 santanoa Dual Screen Empowered     Join Date: Jul 2010 Location: Israel Posts: 258 It seems like there might be a problem if you go through multiple 'hills' or angle changes because your yVel is dependent on your xVel and your xVel is dependent on your yVel. Also, for a 45 degree angle you'd want both xVel and yVel to be the same, right? For your method: If you first change to a 45 degree angle angleRation = 0.5 xVel = 15 yVel = 5 While: xVel = vcos(theta) ==> 7.07 = (10)cos(45) yVel = vsin(theat) ==> 7.07 = (10)sin(45) Hope that makes sense. Good Luck
 07-08-2012, 07:39 AM #9 santanoa Dual Screen Empowered     Join Date: Jul 2010 Location: Israel Posts: 258 Sorry, I didn't see your response... It looks good to me. What's wrong?
 07-08-2012, 12:14 PM #10 ASWC Super Moderator     Join Date: Dec 2007 Location: Greenville, SC Posts: 6,528 A friction joint applies friction to the object you register with it. All other object would keep their normal friction while the object(s) registered with the joint will get your special friction. Once out of the hill you just remove them from the joint and they'll go back to their normal friction values. __________________ aswebcreations Super Duper!

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

All times are GMT. The time now is 03:22 PM.

///