No Velocity
by rennie moffat · in Torque Game Builder · 03/25/2011 (5:08 pm) · 4 replies
Hi there,
I want to give my dragged objects a "smooth" feel, like how most Apple dragged objects appear on the iDevice. They tend to maintain speed then slow to a hault upon lifting the finger off the device. I have started my way of doing it by recording the velocity during onIPhoneMove(). However, when an object is being dragged apparently no velocity is applied to it. The object, according to the engine has none. So how do I get velocity to create the desired illusion with out doing a major rework?
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
This is what I was thinking...
if anyone has any answers on how to do this and would care to share I would appreciate it and or if you have ideas on how it might work.
Cheers.
03/25/2011 (6:02 pm)
I actually just popped the schedule to call from the objects mouse behavior. Records the timer but overall the effect is iffy at best. This is what I was thinking...
function gesturesBehavior::onBehaviorAdd(%this)
{
%this.owner.setUseMouseEvents(true);
$cloud = %this.owner;
}
// This callback is invoked when the cloud is touched or clicked
function gesturesBehavior::onMouseDown(%this, %modifier, %worldPos)
{
//sets global for iPhone gestures in game.cs
$cloudDragging = true;
//records owners position
$cloudOGPos = $cloud.position;
//begins timer to record length of time between down and up mouse events
%this.schedule(100, startTimer);
$timer = 0;
$timerOn = true;
}
function gesturesBehavior::startTimer(%this)
{
if($timerOn)
{
$timer = $timer + 1;
echo("$timer" @ $timer);
%this.schedule(100, startTimer);
}
else return;
}
function gesturesBehavior::onMouseUp(%this, %modifier, %worldPos)
{
$cloudDragging = false;
$timerOn = false;
// record new cloud position
$cloudNowPos = $cloud.position;
///dstCovered is the distance between the original pos and new. original recored on mouseDown
%dstCovered = t2dVectorDistance($cloudOGPos, $cloudNowPos);
echo("$cloudNowPos" @ $cloudNowPos);
echo("%dstCovered" @ %dstCovered);
// then some good old basic newton.
%velocity = %dstCovered / $timer;
echo("%velocity" @ %velocity);
/// to create the smooth damping effect
/// continue with found velocity and dampen to rest.
$cloud.setVelocity(%velocity);
$cloud.setDamping(5);
}if anyone has any answers on how to do this and would care to share I would appreciate it and or if you have ideas on how it might work.
Cheers.
#3
03/28/2011 (3:23 am)
Try onMouseMove rather than onMouseUp/Down. Also, give your cloud some Mass, and Inertia as well as the Damping. Then use setImpulseForce(X,Y) to push it along. Check out the TGB Breakout Tutorial particularly the section on moving the paddle.
#4
Ps. I have solved.
Cheers.
03/28/2011 (9:53 am)
My apologies. I meant to post this in iTGB forums. Ps. I have solved.
Cheers.
Torque Owner rennie moffat
Renman3000
function oniPhoneTouchDown( %touchCount, %touchX, %touchY, %this ) { %this.schedule(100, startTimer); }I have tried with just a local
function oniPhoneTouchDown( %touchCount, %touchX, %touchY ) { %schedule(100, startTimer); }and just as this.
function oniPhoneTouchDown( %touchCount, %touchX, %touchY ) { schedule(100, startTimer); }I need to record the time between down and up events. How can I do this if I can not call a schedule from these function in the game.cs?